Browse Source

Added a Gambling Game

main
fdlt3885 2 years ago
parent
commit
7bb90af3f3
  1. 52
      src/main/quizproject.c
  2. 3
      src/main/quizproject.h

52
src/main/quizproject.c

@ -2451,6 +2451,51 @@ void b_crossword(){
} }
//Gambling Game
void b_gamble()
{
int wallet = 100;
int bet;
int guess;
int number;
srand(time(NULL));
while (wallet > 0) {
printf("You have $%d. Enter your bet: ", wallet);
scanf("%d", &bet);
if (bet > wallet) {
printf("You don't have enough money. Try a smaller bet.\n");
continue;
}
if (bet <= 0) {
printf("Invalid bet. Try again.\n");
continue;
}
printf("Guess a number between 1 and 10: ");
scanf("%d", &guess);
number = rand() % 10 + 1;
if (guess == number) {
printf("You win! The number was %d.\n", number);
wallet += bet;
} else {
printf("You lose. The number was %d.\n", number);
wallet -= bet;
}
}
printf("You are out of money. Better luck next time!\n");
}
void v_play_rockpapersciss(){ void v_play_rockpapersciss(){
int player_choice, computer_choice, player_score = 0, computer_score = 0; int player_choice, computer_choice, player_score = 0, computer_score = 0;
srand(time(NULL)); srand(time(NULL));
@ -2928,7 +2973,8 @@ int main(int argc, char *argv[]) {
printf("15. Germany Quiz!\n"); printf("15. Germany Quiz!\n");
printf("16. Breaking Bad Quiz!\n"); printf("16. Breaking Bad Quiz!\n");
printf("17. Mini-Game: Crossword Puzzle!\n"); printf("17. Mini-Game: Crossword Puzzle!\n");
printf("18. Exit\n");
printf("18. Gambling Game!\n");
printf("19. Exit\n");
printf("Enter your choice: "); printf("Enter your choice: ");
scanf("%d", &choice); scanf("%d", &choice);
v_progress_bar(argc,argv); v_progress_bar(argc,argv);
@ -3003,6 +3049,10 @@ int main(int argc, char *argv[]) {
jump_to_menu = 1; jump_to_menu = 1;
break; break;
case 18: case 18:
b_gamble();
jump_to_menu = 1;
break;
case 19:
printf("\nThank you for trying our C code!\n"); printf("\nThank you for trying our C code!\n");
break; break;
default: default:

3
src/main/quizproject.h

@ -119,6 +119,9 @@ void b_BreakingBquiz();
//Crossword Headers //Crossword Headers
void b_crossword(); void b_crossword();
//Gambling Game Headers
void b_gamble();
#define NUM_QUESTIONS 5 #define NUM_QUESTIONS 5

Loading…
Cancel
Save