diff --git a/src/main/quizproject.c b/src/main/quizproject.c index c5e8e60..2e04172 100644 --- a/src/main/quizproject.c +++ b/src/main/quizproject.c @@ -507,19 +507,32 @@ void play_milliongame() { } void v_guessingGame(void){ - - printf("Guess the Number!\n"); + int secret_number, guess; + srand(time(NULL)); + secret_number = rand() % 100 + 1; + printf("Guess the Number!\n\n"); printf("I am thinking of a number between 1 and 100. Can you guess what it is?\n"); - + while (1) { + printf("Enter your guess: "); + scanf("%d", &guess); + if (guess > secret_number) { + printf("Too high! Try again.\n"); + } else if (guess < secret_number) { + printf("Too low! Try again.\n"); + } else { + printf("Congratulations, you found the secret number!\n"); + break; + } + } } void play_guessingGame() { - printf("**********************\n"); - printf("Playing Guessing Game!\n"); - printf("**********************\n"); + printf("*************************\n"); + printf("Playing Guess the Number!\n"); + printf("*************************\n\n"); v_guessingGame(); printf("****************************************\n"); - printf("Thank you for playing the Guessing Game!\n"); + printf("Thank you for playing Guess the Number!\n"); printf("****************************************\n"); }