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

I\'m trying to make this game of hangman. Initially, there is a word in the arra

ID: 3531157 • Letter: I

Question

I'm trying to make this game of hangman. Initially, there is a word in the array, placed in the main function. The user enters a character, and the program has to determine whether the letter is correct or not, how many times the letter is in the word. I must use 2 or more functions. I designed one function to check whether the letter is correct or not (It will also count the number of times the letter is in the word, and will try - = 1, from 6 tries). The last function will print neccessary sentences for the game.

I DIDN'T CALL ANY OF THE FUNCTIONS INTO MY MAIN, OR THE OTHER FUNCTIONS BECAUSE I THINK THAT IS THE REASON WHY THE PROGRAM STOPS WHEN DEBUGGING. I WILL ADD FUNCTION CALLING LATER. Please give me some advise of how I should improve my program, and help me figure out why the program stops when debugging! (Where should I put the function calling?!!!!!) plz help me! thank you.


#include<stdio.h>


int printer(int answer, int correct, int incorrect, int count, int tries, char star[]){

if(correct = answer){

printf("Letter %s exists %d times in the secret word, You have %d tries left.", answer, count, tries);

printf("%s", star);

}


else{

printf("Letter %s is not part of the secret word, You have %d tries left", answer, tries);

printf("%s", star);


}

}


int lettercheck(char answer, char word[], char star[], int tries){

int i;

char correct = ' ';

char incorrect = ' ';

int count;

for(i = 1; i <= 6; i++){

count = 0;


if(word[i] == answer){


correct = answer;

star[i] = answer;

count++;

}


else{

incorrect = answer;

tries -= 1;

}


}

}


int main(){


char word[] = "rhythem";

char star[] = "******";

char answer = ' ';

int tries = 6;

printf("Hi, let's play hangman. The secret word is: ");

printf("%s ", star);

printf("Guess a letter: ");


if(tries != 0){

scanf("%s", answer);

}

if(tries = 0){

return(0);

}

}


Explanation / Answer

please rate

your modified version of code for the correcr output is

#include<stdio.h>


#include<string.h>

void printer(char answer, char correct, char incorrect, int count, int tries, char star[]){

if(correct ==answer){

printf("Letter %c exists %d times in the secret word, You have %d tries left. ", answer, count, tries);

printf("%s ", star);


}


else{

printf("Letter %c is not part of the secret word, You have %d tries left ", answer, tries);

printf("%s ", star);


}

}


void lettercheck(char answer, char word[], char star[], int& tries){

int i;

char correct=' ';

char incorrect=answer;

int count=0;

for(i = 0; i <=6; i++){



if(word[i] == answer){


correct = answer;

star[i] = answer;

count++;

}



}

tries=tries-1;

printer(answer,correct,incorrect,count,tries,star);

}


int main(){


char word[] = "rhythem";

char star[] = "*******";

char answer=' ';

int tries = 6;


printf("Hi, let's play hangman. The secret word is: ");

printf("%s ", star);

printf("Guess a letter: ");


do

{


scanf("%s",&answer);


lettercheck( answer, word, star, tries);

if(strcmp(star,word)==0)

{

printf("you have sucessfully guesed the word");

}

}while(tries!=0);


return 0;


}