Question

use repl.it intro to C-programing no advance code also put good comment that i can know...

use repl.it intro to C-programing no advance code also put good comment that i can know whats this code use for  thank you

use repl.it intro to C-programing no advance code also put good comment that i can know whats this code use for  thank you

program for a game of hangman. Store the word to be guessed as individual characters of an array called word. The player must guess the letters belonging to word. If the user enters a valid letter, print a message of encouragement. The program should end when the user successfully guesses the word OR after 15 guesses. Print the contents of the word array at the end of the program.

Hint: Use an array called guessed to keep track of the solution so far. Initialize all elements of guessed to the symbol '*'. Each time a letter in word is guessed, replace the corresponding '*' in guessed with that letter.

Sample execution:

Let's play hangman!
Enter a letter: a
The letter a is in the word!
Enter a letter: m
The letter m is in the word!
Enter a letter: r
The letter r is in the word!
The word was: arm

p1

Create the word character array. Get a character from standard input (the user). Search the
character array (string) for how many times that character appears by printing a message when the
letter is found. Also print a message if the letter is not found.

p2

Create the parallel array called guessed. In addition to telling the user they were correct,
replace the * at the corresponding position of word with the correctly guessed letter.

p3

Add a terminating condition using a while loop. The easier condition to implement is a limit of
15 guesses and then the game should terminate and print the array word.

p4

Add an additional terminating condition to your while loop to indicate that the word was guessed
correctly. This condition should be based on guessed having no more * characters in it. Same
as before, if this condition is met, the game should terminate and print the array word.

p5:

Add to your program the ability for a game master to enter a word for a user to guess. Your program
should now be able to use a default (hard coded) word or a word entered by a game master. You can
use a switch case or if statement to let the user select which mode to play the game in.

Homework Answers

Answer #1

code:-

#include <stdio.h>
#include <string.h>

int main() {
// Get word to guess
char answer[128];
printf("lets play hanuman: ");
//fflush(stdout);
scanf(" %s", answer);

// Set the mask array - mask[i] is true if the
// character s[i] has been guessed. The mask
// must be allocated, and initialized to all false
int N = strlen(answer);
int mask[N];
for (int i=0; i < N; ++i) {
mask[i] = 0;
}

// Loop over each round of guessing
int gameover = 0;
while (! gameover) {
// Print word with *s for unguessed letters
printf("Enter the Letter : ");
for(int j=0; j < N; ++j) {
if (mask[j]) {
printf("%c", answer[j]);
}
else {
printf("*");
}
}
printf("\n");

// Get player's next guess
char guess;
printf("Letter? ");
fflush(stdout);
scanf(" %c", &guess);

// Mark true all mask positions corresponding to guess
for(int k=0; k < N; ++k) {
if (answer[k] == guess) {
   mask[k] = 1;
}
}

// Determine whether the player has won!
gameover = 1;
for(int m = 0; m < N; ++m) {
if (!mask[m]) {
gameover = 0;
break;
}
}
}

// Print victory message!
printf("the letter \"%s\".\n", answer ,"is in the world");

return 0;
}

output:-

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g,...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g, char wordlist[][MAX_WORD_LENGTH], int numwords)] for a C program hangman game. (The existing code for other functions and the program is below, along with what the function needs to do) What int setup_game needs to do setup_game() does exactly what the name suggests. It sets up a new game of hangman. This means that it picks a random word from the supplied wordlist array and...
This problem is from Microsoft Visual C#: An Introduction to Object Oriented Programming (7th Edition) by...
This problem is from Microsoft Visual C#: An Introduction to Object Oriented Programming (7th Edition) by Joyce Farrell. This problem relies on the generation of a random number. You can create a random number that is at least min but less than max using the following statements: Random ranNumberGenerator = new Random(); int randomNumber; randomNumber = ranNumberGenerator.Next(min, max); Create a game similar to Hangman named GuessAWord in which a player guesses letters to try to replicate a hidden word. Store...
Data Encryption (Strings and Bitwise Operators) Write a C program that uses bitwise operators (e.g. bitwise...
Data Encryption (Strings and Bitwise Operators) Write a C program that uses bitwise operators (e.g. bitwise XOR) to encrypt/decrypt a message. The program will prompt the user to select one of the following menu options: 1. Enter and encrypt a message 2. View encrypted message 3. Decrypt and view the message (NOTE: password protected) 4. Exit If the user selects option 1, he/she will be prompted to enter a message (a string up to 50 characters long). The program will...
THIS IS FOR JAVA I have to write a method for a game of Hangman. The...
THIS IS FOR JAVA I have to write a method for a game of Hangman. The word the user is trying to guess is made up of hashtags like so " ###### " If the user guesses a letter correctly then that letter is revealed on the hashtags like so "##e##e##" If the user guesses incorrectly then it increments an int variable named count " ++count; " String guessWord(String guess,String word, String pound) In this method, you compare the character(letter)...
n this lab, you use what you have learned about parallel arrays to complete a partially...
n this lab, you use what you have learned about parallel arrays to complete a partially completed C++ program. The program should: Either print the name and price for a coffee add-in from the Jumpin’ Jive Coffee Shop Or it should print the message Sorry, we do not carry that. Read the problem description carefully before you begin. The file provided for this lab includes the necessary variable declarations and input statements. You need to write the part of the...
USE C++!!!! Encryption and Decryption are two cryptographic techniques. Encryption is used to transform text to...
USE C++!!!! Encryption and Decryption are two cryptographic techniques. Encryption is used to transform text to meaningless characters, and decryption is used to transform meaningless characters into meaningful text. The algorithm that does the encryption is called a cipher. A simple encryption algorithm is Caesar cipher, which works as follows: replace each clear text letter by a letter chosen to be n places later in the alphabet. The number of places, n, is called the cipher key. For example, if...
Write a code in c++ using linear insertion following the steps below. Comment your work. 1....
Write a code in c++ using linear insertion following the steps below. Comment your work. 1.    Ask the user for the name of a file containing data. If it does not exist, the program should display an error, then ask for a new file name. Entering an asterisk (*) as the first and only character on a line should terminate the program. 2.     You can use a statically-allocated one-dimensional array of doubles for this with length 100. You...
Note: Do not use classes or any variables of type string to complete this assignment Write...
Note: Do not use classes or any variables of type string to complete this assignment Write a program that reads in a sequence of characters entered by the user and terminated by a period ('.'). Your program should allow the user to enter multiple lines of input by pressing the enter key at the end of each line. The program should print out a frequency table, sorted in decreasing order by number of occurences, listing each letter that ocurred along...
C Code! dictionary.c, start by downloading the boilerplate1 code from Blackboard. Read the code, then complete...
C Code! dictionary.c, start by downloading the boilerplate1 code from Blackboard. Read the code, then complete it at all places indicated by TODO. For this second assignment, you do not receive precise specifications. This is on purpose: in the software industry, you’ll find a lot of cases when you need to finish code started by others, while not being given precise instructions on how the code works or is supposed to work. The comments in the code will help you,...
The code I have written runs but I need it us UDP not TCP. Also I...
The code I have written runs but I need it us UDP not TCP. Also I just need someone to check my work and make sure that it works properly. The python code needs to be run with command line so you can add more than one client. The directions: 1. The chat is performed between 2 clients and not the server. 2. The server will first start up and choose a port number. Then the server prints out its...