Question: Part B: C Programming Exercise ( 5 marks ) a ) Write a C program that generates a random number between 0 and 5 0

Part B: C Programming Exercise (5 marks)
a) Write a C program that generates a random number between 0 and 50. Then, the program prompts for guesses until the user is correct, or has made 10 wrong guesses. After each guess, the program indicates whether the guess was too high, too low, or correct. Once the round has ended, either by a correct guess or by using up the 10 guesses, the program displays the current status.
b) Save your program to a file named "guessGame.c" in the working directory on the PC you are using.
c) Demonstrate the guessGame.c file to GA/TAs and run with different input values.
Hint: To generate a random number between 1 and 50 in C, first, add \#include to your code and then use the following statement:
\[
\text { int goal }=\text { rand }()\%50+1 ;
\]
Assuming the random number is 48, a sample interaction is shown below
Enter your guess (between 1 and 50): \(\mathbf{30}\)
Too low ...
Enter your guess (between 1 and 50): \(\mathbf{50}\)
Too high ...
Enter your guess (between 1 and 50): 48
Correct, the number was 48.
If the user entered more than 10 wrong guesses:
Sorry, the number was 48.
Part B: C Programming Exercise ( 5 marks ) a )

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 Programming Questions!