Question

I would appreciate if i could get help with creating Hangman code for C++ in visual...

I would appreciate if i could get help with creating Hangman code for C++ in visual studio.

It must include: vector, operator, Classes,string
option to read random word for guessing in txt file would be plus , also line for hangin for wrong word if possible.

thanks
regards

0 0
Add a comment Improve this question Transcribed image text
Answer #1

This is a simple Hangman code from which you will start getting ideas on how to implement further in this program

/*
Simple hangman game
Do not use caps
*/

#include <iostream>
#include <string>
using namespace std;

int main()
{
cout << "Enter the word for other player to guess" << endl;
  
string word;
getline(cin, word);
  
string copy = word;

string Underscore;
  
for(int i=0; i!=word.length(); i++){

if(word.at(i) == ' '){
Underscore += " ";
} else{
Underscore += "_";
}
}
  
for(int i=0; i!=50; ++i){
cout << endl;
}
  
string guess;
int wrong=0;
  
while(1){
if(wrong == 6){
cout << "You Lose! The word was: " << word << endl;
break;
}

cout << Underscore << endl;
cout << "There are " << word.length() << " letters with spaces" << endl;
cout << "You have " << 6 - wrong << " more tries left" << endl;

if(Underscore == word){
cout << "You win!" << endl;
break;
}

cout << "Guess a letter or a word" << endl;
getline(cin, guess);
  
if(guess.length() > 1){
if(guess == word){
cout << "That's right, you win!" << endl;
break;
} else{
cout << "wrong word " << endl;
wrong++;
}
} else if(copy.find(guess) != -1){
while(copy.find(guess) != -1){
Underscore.replace(copy.find(guess), 1, guess);
copy.replace(copy.find(guess), 1, "_");
}
} else{
cout << "That's wrong" << endl;
wrong++;
}
  
cout << endl;
}
return 0;
}

Add a comment
Know the answer?
Add Answer to:
I would appreciate if i could get help with creating Hangman code for C++ in visual...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Help please, write code in c++. The assignment is about making a hangman game. Instructions: This...

    Help please, write code in c++. The assignment is about making a hangman game. Instructions: This program is part 1 of a larger program. Eventually, it will be a complete Hangman game. For this part, the program will Prompt the user for a game number, Read a specific word from a file, Loop through and display each stage of the hangman character I recommend using a counter while loop and letting the counter be the number of wrong guesses. This...

  • hey dear i just need help with update my code i have the hangman program i...

    hey dear i just need help with update my code i have the hangman program i just want to draw the body of hang man when the player lose every attempt program is going to draw the body of hang man until the player lose all his/her all attempts and hangman be hanged and show in the display you can write the program in java language: this is the code bellow: import java.util.Random; import java.util.Scanner; public class Hangmann { //...

  • I need this in Visual Studio C++ Write a function that count the number of vowels,...

    I need this in Visual Studio C++ Write a function that count the number of vowels, the number of consonants and the average number of letters in each word. The function accept a C-String (char array) or a string object as an argument and return the number of vowels, number of consonants and the average number of letters in each word. Problem: Requirements: . Use pointers as part of the solution Read a string from a text file. . Write...

  • For a C program hangman game: Create the function int play_game [play_game ( Game *g )]...

    For a C program hangman game: Create the function int play_game [play_game ( Game *g )] 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) (Also the link to program files (hangman.h and library file) is below the existing code section. You can use that to check if the code works) What int play_game needs to do mostly involves calling other functions you've already...

  • c++. I'm working on a hangman game. It has to utilize a class. It should show...

    c++. I'm working on a hangman game. It has to utilize a class. It should show the number of attempts that have been made, the length of the word represented by dots, and then the alphabet. There also needs to be input validation. If the word was horse, the very first attempt at the user guessing should display " 1 ..... choose: abcdefghijklmnopqrstuvwxyz ". As the user guesses letters, the number of attempts should go up, the letter should be...

  • I have this section of code for a Morse Code Converter with C# (Visual Studio) that...

    I have this section of code for a Morse Code Converter with C# (Visual Studio) that I can't figure out. I have a two-dimensional array containing the character and correlated Morse Code. I need loops to step through the Input message, search through the array to fins the corresponding character and Morse Code, then append the Morse Code to the Morse code string. (Below is the code I need help with. Thanks!) // Set up a loop to 'step through'...

  • The code will not run and I get the following errors in Visual Studio. Please fix the errors. err...

    The code will not run and I get the following errors in Visual Studio. Please fix the errors. error C2079: 'inputFile' uses undefined class 'std::basic_ifstream<char,std::char_traits<char>>' cpp(32): error C2228: left of '.open' must have class/struct/union (32): note: type is 'int' ): error C2065: 'cout': undeclared identifier error C2065: 'cout': undeclared identifier error C2079: 'girlInputFile' uses undefined class 'std::basic_ifstream<char,std::char_traits<char>>' error C2440: 'initializing': cannot convert from 'const char [68]' to 'int' note: There is no context in which this conversion is possible error...

  • I need help with this. I need to create the hangman game using char arrays. I've...

    I need help with this. I need to create the hangman game using char arrays. I've been provided with the three following classes to complete it. I have no idea where to start. HELP!! 1. /** * This class contains all of the logic of the hangman game. * Carefully review the comments to see where you must insert * code. * */ public class HangmanGame { private final Integer MAX_GUESSES = 8; private static HangmanLexicon lexicon = new HangmanLexicon();...

  • This is for my c++ class and I would really appreciate the help, Thank you! Complete...

    This is for my c++ class and I would really appreciate the help, Thank you! Complete the definitions of the functions for the ConcessionStand class in the ConcessionStand.cpp file. The class definition and function prototypes are in the provided ConcessionStand.h header file. A testing program is in the provided main.cpp file. You don’t need to change anything in ConcessionStand.h or main.cpp, unless you want to play with different options in the main.cpp program. ___________________ Main.cpp ____________________ #include "ConcessionStand.h" #include <iostream>...

  • Python Problem Hello i am trying to finish this code it does not save guesses or...

    Python Problem Hello i am trying to finish this code it does not save guesses or count wrong guesses. When printing hman it needs to only show _ and letters together. For example if the word is amazing and guess=a it must print a_a_ _ _ _ not a_ _ _ _ and _a_ _ _ separately or with spaces. The guess has a maximum of 8 wrong guesses so for every wrong guess the game must count it if...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT