Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write an interactive program that plays a game of hangman. Store the characters of the word to be guessed in an array of type char

Write an interactive program that plays a game of hangman. Store the characters of the word to be guessed in an array of type char (you can initialize your character array at declaration). Words are seven letters long. Initially, the program displays the length of the word to be guessed. This is in the form of successive stars (see example). The player guesses letters belonging to the secret word one by one. After each guess, the letters that have been guessed and the number of wrong guesses are displayed on the screen. Your program should terminate when either the entire word is guessed or 4 incorrect guesses have been attempted.

Your code shall use the following function:

bool letterCheck(char secret[], char found[], int len, char c, int *times); 

The function receives as input array secret that holds the secret word, array found that holds the letters that have been found thus far, the length of the secret word, and the input character from the user. The function returns if the letter given by the user was found in array secret (via the boolean return variable), updates array found, and also returns the number of times the letter was found via pointer times

Test your program for the words: abandon, annoyed, finance, aerobic, inferno, infancy.

Sample output Hi, lets play hangman. The secret word is: ******* Guess a letter:t Letter t is not part of the secret word, You have 3 attempts left. ******* Guess a letter:a Letter a exists 2 times in the secret word, You have 3 attempts left. a*a**** Guess a letter:e Letter e is not part of the secret word, you have 2 attempts left.

image text in transcribed

LAB ACTIVITY 17.14.1: Homework 6, P2: Hangman 0/2 main.c Load default template... 1 #include 2 3 bool letterCheck(char x[], char y[], int len, char s, int *times); 4 5 int main() { 6 7 /* Type your code here. */ 8 9 return 0; 10} 11 12 bool letterCheck(char x[], char y[], int len, char c, int *times) { 13 // checks if letter c exists in x[]. Discovered letters are stored in y[]. 14 //times holds how many 15 // times c appeared in x. 16 17 } 18 19

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Accounting And Auditing Research And Databases Practitioner's Desk Reference

Authors: Thomas R. Weirich, Natalie Tatiana Churyk, Thomas C. Pearson

1st Edition

1118334426, 978-1118334423

More Books

Students also viewed these Databases questions

Question

What is cost accounting? Why is it important in business?

Answered: 1 week ago