Question: /** * This program plays a guessing game with the user. * It selects a random number between 1 and 1000 and * prompts the

/** * This program plays a guessing game with the user. * It selects a random number between 1 and 1000 and * prompts the user to guess the value, informing them * of whether or not it is higher or lower than the * actual value. Once the user guesses correctly, the * game ends and the number of guesses is displayed. * */ #include#include #include int main(int argc, char **argv) { // the game will be played by creating a random // number between 1 and 1000 int n = 1000; // seed the random number generator srand(time(NULL)); // the program generates a random number between 1 and 1000 // the user will try to guess what this number is int number = (rand() % n) + 1; // initialize the user's "guess" to be an invalid value int guess = -10; int numGuesses = 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 ", numGuesses); return 0; }
Number Guessing Game Shall we 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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
