diff --git a/src/main/quizproject.c b/src/main/quizproject.c index fecb093..638b736 100644 --- a/src/main/quizproject.c +++ b/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(){ int player_choice, computer_choice, player_score = 0, computer_score = 0; srand(time(NULL)); @@ -2928,7 +2973,8 @@ int main(int argc, char *argv[]) { printf("15. Germany Quiz!\n"); printf("16. Breaking Bad Quiz!\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: "); scanf("%d", &choice); v_progress_bar(argc,argv); @@ -3003,6 +3049,10 @@ int main(int argc, char *argv[]) { jump_to_menu = 1; break; case 18: + b_gamble(); + jump_to_menu = 1; + break; + case 19: printf("\nThank you for trying our C code!\n"); break; default: diff --git a/src/main/quizproject.h b/src/main/quizproject.h index 311b7fc..65cd017 100644 --- a/src/main/quizproject.h +++ b/src/main/quizproject.h @@ -119,6 +119,9 @@ void b_BreakingBquiz(); //Crossword Headers void b_crossword(); +//Gambling Game Headers +void b_gamble(); + #define NUM_QUESTIONS 5