Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Driven Web Sites

Authors: Mike Morrison, Joline Morrison

1st Edition

061901556X, 978-0619015565

More Books

Students also viewed these Databases questions

Question

How should Grandview go about implementing a global rewards system?

Answered: 1 week ago

Question

Explain Coulomb's law with an example

Answered: 1 week ago

Question

What is operating system?

Answered: 1 week ago

Question

What is Ohm's law and also tell about Snell's law?

Answered: 1 week ago

Question

Explain the function and purpose of the Job Level Table.

Answered: 1 week ago