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

PLEASE READ INSTRUCTIONS FIRST! DO NOT COPY AND PASTE YOUR CODE. TAKE A SCREENSH

ID: 3544307 • Letter: P

Question

PLEASE READ INSTRUCTIONS FIRST! DO NOT COPY AND PASTE YOUR CODE.TAKE A

SCREENSHOT OF THE CODE AND SHOW THAT IT

WORKS. DO NOT COPY AND PASTE THE CODE AS A

TEXT.

Write an interactive program that plays a game of hangman. Store the word to be guessed in in successive elements of an array of individual characters called word. The player must guess the letters belonging to word. The program should terminate when either all letters have been guess have been made (the computer wins). Use another array named guessed to keep track of the solution so far. Initialize all elements of guessed to the '*' character. Each time a letter in word is guessed, replace the corresponding '*' in guessed with that letter. Hint: You can just use a word of your choosing for the word to be guessed. Use at least two functions to implement the game.

Explanation / Answer

Here is working proof : http://ideone.com/7DsOuP

#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