Question
Activity 3: Number Guessing Game Lets play a game. In this game, a computer program randomly generates a number between 1 and 1,000. You, the
Activity 3: Number Guessing Game
Lets play a game. In this game, a computer program randomly generates a number between 1 and 1,000. You, the player, then make guesses as to what that number is. If you guess correctly, the game ends and you win. For each wrong guess, the computer program gives you a hint by telling you whether your guess is too low or too high. The goal is to minimize the number of guesses you make. We have provided an incomplete program, guessingGame.c that randomly generates a number between 1 and 1,000. You need to write a loop structure that prompts the user for a guess. While that guess is wrong, the loop should continue. It should also keep track of how many guesses the user makes and, for each wrong guess it should print the appropriate hint to the user. Complete the program.
#include #include #include
int main(void) {
int n = 1000;
//seed the random number generator srand(time(NULL)); int number = (rand() % n) + 1;
int guess = -10; int num_guesses = 0;
printf("Guess-A-Number Game! "); printf("Enter a number between 1 and %d ", n);
//TODO: place your code here
printf("Congratulations, you found it! Number of guesses: %d ", num_guesses); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started