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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!