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

Make sure you have use all of this functions use this function: int generate Num

ID: 3538210 • Letter: M

Question

Make sure you have use all of this functions

use this function: int generate Number(void)

                             int displayMenu(void)

                              int check_error(int guess)

                             int checkGuess(int guess, int answer)

                            void printResult(int result, int answer)

Note: make sure to check both of the sample outputs

sample out

please guess a color

color options are:

0: Green

1: Red

2: Blue

3: Yellow

Enter your choice: 32

Invalid guess enter your choice again:3

your guess was incorrect

Correct answer was Red

sample out

please guess a color

color options are:

0: Green

1: Red

2: Blue

3: Yellow

Enter your choice: 12

Invalid guess enter your choice again:-12

Invalid guess enter your choice again:3

your guess was incorrect

Correct answer was Red

Explanation / Answer

#include<stdio.h>

int generateNumber(void);
int displayMenu(void);
int check_error(int guess);
int checkGuess(int guess, int answer);
void printResult(int result, int answer);

void main(void)
{
int guess,result,answer;
answer = generateNumber();
displayMenu();
printf(" Enter your choice ");
scanf("%d",&guess);
while(check_error(guess))
{
scanf("%d",&guess);
}
result = checkGuess(guess,answer);
printResult(result,answer);
return;
}

int generateNumber(void)
{
int answer;
answer = rand() % 4;

return answer;
}

int displayMenu(void)
{
printf("please guess a color ");
printf("color options are: ");
printf("0: Green 1: Red 2: Blue 3: Yellow ");
return 1;
}

int check_error(int guess)
{
if (guess>3)
{
printf("Invalid guess enter your choice again:");
return 1;
}
return 0;
}

int checkGuess(int guess, int answer)
{
if(guess==answer)
{
return 1;
}
else
return 0;
}

void printResult(int result, int answer)
{
if(result == 1)
{
printf("Your guess was correct ");
}
else
{
printf("Your guess was incorrect ");
}

if(answer == 0 )
printf("Correct answer was Green ");
if(answer == 1 )
printf("Correct answer was Red ");
if(answer == 2 )
printf("Correct answer was Blue ");
if(answer == 3 )
printf("Correct answer was Yellow ");
return;
}

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