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...
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...
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...
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...
COMPLETE IN C++ Declare and initialize a global constant named SIZE with the value 50. Write...
COMPLETE IN C++ Declare and initialize a global constant named SIZE with the value 50. Write a void function called count that accepts two parameters-- a C-string called str representing a C-string passed to the function and an array of integers called alphabets to store the count of the letters of the C-string. Note that the alphabets array stores 26 counters – one for each letter of the alphabet. Use the same counter for lowercase and uppercase characters. The first...
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...
WRITE C++ PROGRAM FOR 1,2,3,4 PARTS of question, DO ADD COOMENTS AND DISPLAY THE OUTPUT OF...
WRITE C++ PROGRAM FOR 1,2,3,4 PARTS of question, DO ADD COOMENTS AND DISPLAY THE OUTPUT OF A RUNNING COMPILER QUESTION: 1) Fibonacci sequence is a sequence in which every number after the first two is the sum of the two preceding ones. Write a C++ program that takes a number n from user and populate an array with first n Fibonacci numbers. For example: For n=10 Fibonacci Numbers: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 2): Write...
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...
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)...
Program Behavior Each time your program is run, it will prompt the user to enter the...
Program Behavior Each time your program is run, it will prompt the user to enter the name of an input file to analyze. It will then read and analyze the contents of the input file, then print the results. Here is a sample run of the program. User input is shown in red. Let's analyze some text! Enter file name: sample.txt Number of lines: 21 Number of words: 184 Number of long words: 49 Number of sentences: 14 Number of...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT
Active Questions
  • research acquisitions that are currently underway and choose one of these acquisitions to discuss. Based on...
    asked 7 minutes ago
  • Java question The class _________ in the java.util package makes it easy to read and tokenize...
    asked 10 minutes ago
  • CSP Question You are in charge of scheduling for computer science classes that meet Mondays, Wednesdays...
    asked 23 minutes ago
  • •Write a program which control value of the robot. The charging min value is zero and...
    asked 26 minutes ago
  • A cylindrical metal can, 0.1 m high and 0.05 m in diameter, contains liquid helium at...
    asked 26 minutes ago
  • Find the average binding energy per nucleon of 92 42 Mo and 82 36 Kr. Enter...
    asked 33 minutes ago
  • A 1.89 mole sample of Ar undergoes an isothermal reversible expansion from an initial volume of...
    asked 46 minutes ago
  • The OECD cut forecasts again for the global economy in 2019 and 2020, following on from...
    asked 47 minutes ago
  • Constructa2-3treeforthelistC,O,M,P,U,T,I,N,G.Usethealphabetical order of the letters and insert them successively starting with the empty tree.
    asked 57 minutes ago
  • Given class Function {     public:     virtual double compute(double value) = 0;     virtual double differentiate(double value) =...
    asked 1 hour ago
  • Create a C# program named PaintingEstimate whose Main() method prompts a user for length and width...
    asked 1 hour ago
  • Gubser Welding, Inc., operates a welding service for construction and automotive repair jobs. Assume that the...
    asked 1 hour ago