Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assume a user is playing guessing number game.Write a C program that will ask th

ID: 3650853 • Letter: A

Question

Assume a user is playing guessing number game.Write a C program that will ask the user to guess a secret number A (which is generated by the program).A is between 1 and 50.The program then accepts user's guessing number from keyboard.After user enters his guessing,the program will give a response that "your input is larger" if user's guessing is bigger than A, "your input is smaller" is user's guessing is smaller than A,and "guess correctly" if user's guessing is exact A.

In the function main do the following:
1)Call function guessingNumber
2)In guessingNumber function call getInteger function to obtain user's input.The getInteger function returns the integer inputted by the user.Give response(as said above) until the user guess correctly.
3)Function guessingNumber returns an integer which records how many times user 2 used to guess A correctly, and prints the secret number to the screen.(Note:a WHILE LOOP IS NEEDED)
4)Print how many times it takes user to make a correct guess on A
5)Call function printMenu:void printMenu(void);

the output of printMenu should look like follows:

G ->Start another guessing;

Others ->Exit;

6)The user should be able to start another guessing by choosing 'G/g'.Or the user can terminate the program by choosing other characters.

Explanation / Answer

#include #include #include int guessingNumber(int); int getInteger(int); void printMenu(); int main(){ int A, numguess; srand(time(NULL)); while(1){ A=rand()%50 +1; //rand:[0-49] +1 =[1-50] numguess=guessingNumber(A); printf(" It took user %d guesses to guess %d",numguess,A); printMenu(); } return 0; }//end of main; int guessingNumber(int answer){ int guess=answer+1; int count=0; while(guess!=answer){ guess=getInteger(answer); count++; } printf(" The secret number is: %d",answer); return count; } int getInteger(int A){ int input; printf(" Enter a guess: "); scanf("%d",&input); if(input==A){ printf(" guess correctly"); } else if(input>A){ printf(" your input is larger"); } else printf(" your input is smaller"); return input; } void printMenu(){ char key; printf(" G ->Start another guessing; Others ->Exit;"); key=getchar(); if(key=='G' || key=='g'){ return; } else exit; }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote