Question: Modify the program you have to update the function startHangmanGame to implement the Hangman game, which works as follows: The program asks the user to

Modify the program you have to update the function startHangmanGame to implement the Hangman game, which works as follows: The program asks the user to select a category from one of the following: 1. Food. 2. Objects. 3. Names. 4. Colors.

Modify the program you have to update the function startHangmanGame to implement

If the user enters one of the 4 numbers, the program will select a word from that category to play. If the user enters any other number, the program will display an error message "Invalid choice." and redisplay the categories and wait for a valid choice. The program will use the provided files [food.txt, objects.txt, names.txt, colors.txt] which contain 15 words each to select a word from the user-selected category. The selected word should be chosen in random. You can use the rand function to generate random numbers in C, here is an example:

the Hangman game, which works as follows: The program asks the user

After the random word is chosen from the file that corresponds to the chosen category, the program will display underscores that correspond to the hidden word characters, along with the remaining attempts as shown in Figure

to select a category from one of the following: 1. Food. 2.

The word in the Figure above contains 4 letters only, and the user has 5 attempts. Then, the user enters a letter, the program checks whether this letter exists in the word or not. If it does not exist, the program will deduct 1 from the remaining attempt and redisplay the previous message again as shown on Figure

Objects. 3. Names. 4. Colors. If the user enters one of the

If the character exists in the word, the program will replace the underscore in that character's position with the character and redisplay the previous message as shown in Figure

4 numbers, the program will select a word from that category to If the number of attempts gets to zero, a hard luck message will be printed to the user as shown in Figure and the game will exit to the main menu. Figure

play. If the user enters any other number, the program will display If the user finds all the letters before running out of attempts, a congratulations message will be printed to the user as shown in Figure and the game will exit to the main menu.

an error message "Invalid choice." and redisplay the categories and wait for

Choose a category: 1. Food. 2. Objects. 3. Names. 4. Colors. #include #include #include int main() { // to generate different numbers in each run // for this program srand(time(NULL)); // generates a random number between 0 and 14 int x = rand() $ 15; printf("%d ", x); return 0; } The word so far is: ---- You have 5 remaining attempts. Not quite! Try again! The word so far is: --- You have 4 remaining attempts. i Correct! keep going! The word so far is: --_i. You have 4 remaining attempts. a Hard luck! You were not able to find the word. :( Congratulations! You found the word

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!