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

Write an interactive program that plays the game of Hangman. Read the word to be

ID: 3591742 • Letter: W

Question

Write an interactive program that plays the game of Hangman. Read the word to be guessed into word. The player must guess the letters belonging to word. The program should terminate when either all let- ters have been guessed correctly (player wins) or a specified number of incorrect guesses have been made (computer wins). (Hint: Use solu- tion to keep track of the solution so far. Initialize solution to a string of symbols '*'. Each time a letter in word is guessed, replace the cor- responding in solution with that letter.)

Explanation / Answer

#include <stdio.h>

int check(char word[],char temp[],char guess[],int n);

int match(char word[],char guess[],int n);

int main(void) {

int i,n=5,chance,win=0;

char temp[n+1],guess[n+1];

char word[]="peace";// size of the word is n

chance=10;

printf("Lets Start , Word has %d character in it. You have got %d chances ",n,chance);

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

guess[i]='*';

guess[i]='';

while(chance--)

{

printf("please enter guessing word & then press enter ");

printf("You guess till now is " %s " ",guess);

scanf("%s ",temp);

printf("You have entered " %s " ",temp);

check(word,temp,guess,n);

win=match(word,guess,n);

if(win) break;

}

if (win) printf("You Won ");

else printf("You Lost ");

return 0;

}

int check(char word[],char temp[],char guess[],int n)

{

int i;

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

{

if (temp[i]==word[i])

{

guess[i]=word[i];

}

}

return 1;

}

int match(char word[],char guess[],int n)

{

int i;

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

{

if (guess[i]!=word[i])

{

return 0;

}

}

return 1;

}

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