Question: Write a C language program that allows a user to guess a random number between 1 and 1000. The function rand() from the header file
Write a C language program that allows a user to guess a random number between 1 and 1000. The function rand() from the header file can be used for this purpose. Before using the function, the random number generator must be provided a seed value to set it up. If the same seed value is supplied each time the program is run, the results of the random number generator will come out in the same order each time. A commonly used seed value is derived from the system clock, because the seconds count changes frequently enough to provide a different seed value each time we run the program. Include this in the beginning of your main program to seed the RNG: srand(time(NULL)); To use the time function, must be included. The rand() function returns a random integer between 0 and 32767. You will need to adjust the result to be between 1 and 1000 (think about how we might do this). Use a while loop to keep looping whenever the user guesses incorrectly. The loop should terminate when the user guesses the number correctly. Your program should count and print the number of guesses by the user. Each time the user guesses a number, you should print one of the following messages: Good guess. Too low, try again. Too high, try again. Sample Output: Guess my number 500 Too low, try again. Guesses: 1 750 Too high, try again. Guesses: 2 625 Too low, try again. Guesses: 3 675 Good guess. Guesses: 4
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
