Ejemplo n.º 1
0
//this function is the pick a number game
int pick_a_number() {
  int pick, winning_number;

  printf("\n###### Pick a Number ######\n");
  printf("This Game costs 10 credits to play. Pick a Number\n");
  printf("between 1 and 20, and if you pick the winning number you win jackpot of 100 credits\n\n");
  winning_number = (rand() % 20) + 1;
  if(player.credits < 10) {
    printf("You only have %d credits. Thats not enough to play\n\n", player.credits);
    return -1;
  }
  player.credits -= 10;
  printf("10 credits have been deducted from you account\n");
  printf("Pick a number between 1 and 20:  ");
  scanf("%d", &pick);

  printf("the winning number is %d\n", winning_number);
  if(pick == winning_number)
    jackpot();
  else
    printf("You Didn't win\n");
  return 0;
}
Ejemplo n.º 2
0
// This function is the Pick a Number game.
// It returns -1 if the player doesn't have enough credits.
int pick_a_number() { 
	int pick, winning_number;

	printf("\n####### Pick a Number ######\n");
	printf("This game costs 10 credits to play. Simply pick a number\n");
	printf("between 1 and 20, and if you pick the winning number, you\n");
	printf("will win the jackpot of 100 credits!\n\n");
	winning_number = (rand() % 20) + 1; // Pick a number between 1 and 20.
	if(player.credits < 10) {
		printf("You only have %d credits. That's not enough to play!\n\n", player.credits);
		return -1;  // Not enough credits to play 
	}
	player.credits -= 10; // Deduct 10 credits.
	printf("10 credits have been deducted from your account.\n");
	printf("Pick a number between 1 and 20: ");
	scanf("%d", &pick);

	printf("The winning number is %d\n", winning_number);
	if(pick == winning_number)
	      jackpot();
	else
	      printf("Sorry, you didn't win.\n");
	return 0;
}