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

T-Mobile LTE 2:58 PM 75%- + Dua Project 2.pdf General Requirements for project 2

ID: 3740668 • Letter: T

Question

T-Mobile LTE 2:58 PM 75%- + Dua Project 2.pdf General Requirements for project 2 . Rewrite the program from projoct I using at least four programmer-definod functions other than the main function All functions (escept the main function) will be defined as follows o The function prototype appears before the main o Comment describing what the functson does appers directly under function pelotype o Formal variable names are not used in any prototype o The functions definition appears a after the main The first function's mame is introduction, which will peint (show on the screcn) Welcome to the Letter Guessing Game You will enter the number of games you want toplay(s-4 games) You have schances to guess each letter Let'sbegin The seoond function's name is getNumberOiiame, which asks the user about the number of games to be played and returns the value. This function will validate the user input to make sure it is in the dsired ran(-4) inclusive, if the valu is out of range the user is notifiod and askod again . How many games do you want toplay (4)3 The third function's name is compareTwoCharacters, which receives two parameters of type character (eg the character to be guessed in that game and the character typed by the user). This functioes rcturn 0 if the two characters are the same, returns 2 if the first parameter comes aher the second parameter, otherwise it returns -2 The fourth function's name is playOncGame, which receives one parameter of type character (the character to be guessed in that game). This function returns true if the user won otherwise will return false. This function will handle all tasks to play one game (ask the wser to mtcr their guess, provide up to 5 chances l, guess, provide a hin", the-ser, etc). This fanction gomg to call the third function (Le. compare TwoCharacters) to decide if the user has guessed the cormect answer or to peovide a hint to the user .Make sure to follow the instructions carefully including wsing the esact function names with the exact leter cases (upper and lower case letters). Your programs are poing to be tedod using a unified main function that is developed foe that purpose. lf the unified main function does not compile tdhis indicales inconsistencies in meeting the above requirements and will result in a ero grade.

Explanation / Answer

#include<stdio.h>

void introduction();

int getNumberOfGame();

void playOneGame(char);

int compareTwoCharacters(char,char);

int main()

{

introduction();

int num=getNumberOfGame();

int i;

for( i=0;i<num;i++)

{

int n = rand()%26;

char c = (char)(n+91);

printf("**************************** ");

printf("Let's play game %d ",i+1);

playOneGame(c);

}

}

void introduction()

{

printf("Welcome to the Letter Guessing Game ");

printf("You Will enter the number of games you wnat to play(1-4 games) ");

printf("You have 5 chances to guess each letter ");

printf("Let's begin ");

}

int getNumberOfGame()

{

printf("How many games do you want to play(1-4)::");

int num;

scanf("%d",&num);

if(num>=1 && num<=4)

return num;

else

{

printf("Enter valid number ");

getNumberOfGame();

}

}

void playOneGame(char ch)

{

int flag=0;

int k;

char gu;

for(k=0;k<5;k++)

{

printf("Enter a guess::");

scanf(" %c",&gu);

int cmp=compareTwoCharacters(ch,gu);

if(cmp==0)

{

printf("You guessed it!! ");

flag++;

k=5;

}

else if(cmp==2)

printf("the letter you are trying to guess comes after %c ",gu);

else

printf("the letter you are trying to guess comes before %c ",gu);

}

if(flag==0)

printf("You did not guess the letter it was %c ",ch);

}

int compareTwoCharacters(char ch,char gu)

{

int te1=(int)ch;

int te2=(int)gu;

if(te1==te2)

return 0;

else if(te1>te2)

return 2;

else

return -2;

}