Question

Hangman using while and fo loops, if's, and functions.

I would like to preface this by saying this is NOT a current homework assignment; but it is an assignment from 3 years ago before I dropped out of school. I am self teaching and am revisiting an old assignment. I am NOT asking for the entire program, I'm simply looking for help building the skeleton for the initial start of the game.

MORE INFO: Player 1 will enter word(of any length / i have been using "Testing") for Player 2 to guess. Player 2 will have 5 letter guesses, and 5 word guesses. If Player 2 enters "Testing" it should be able to ignore the case between upper/lower (WITHOUT using toupper / tolower) IF: Player 2 enters more than 1 letter for a guess: "aa" make them guess again until they only guess 1 letter "a".

The problems I'm facing is: I don't know where to place everything, I feel I'm mixing up or messing up the functions, and everytime I try to organize it, it only gets worse. I've restarted it several times, I'm just having trouble getting it all laid out.

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

int main()
{
    string word, wordguess, lower, dashes;
    string letterguess;
    int i = 0;
    bool GameOver = false, Validletterguess = true, Validwordguess = true;


    cout << "Player 1, enter a word for Player 2 to guess: " << endl;
    getline(cin, word);
    cout << endl;
    cout << "Player 2, you have 5 letter guesses, and 5 word guesses." << endl;
    cout << "Guess your first letter: " << endl;

    while (GameOver == false) // Start of Game. Setup for Round 1 letter guess and word guess.
    {

        while (letterguess.length() != 1) // 1 letter per guess. If user enter "a" good input. If user enter "aa" or nothing, bad input, loop until good input. 
        {
            cout << endl << "Type a single letter and press <enter>: ";
            cin >> letterguess;   // enter first letter guess          

            for (int i = 0; i < letterguess.length(); i++) //ignore case of letter guess? idk where to put this
            {
                if (letterguess.at(i) >= 'A' && letterguess.at(i) <= 'Z')
                {
                    lower += letterguess.at(i) + 32;
                }
                else
                {
                    lower += letterguess.at(i);
                }
            }
            if (letterguess.at(i) == word.at(i) && Validletterguess == true) //if Player2 guesses a correct letter, replace the dash with letter and display location: ex. If "T" then "You guessed the 1st and 4th letter"
            {
                cout << "You guessed the first letter right!" << endl; // figure out how to display dashes? 
                dashes.at(i) = letterguess.at(i);
                cout << "Enter your first word guess: " << endl;
                cin >> wordguess;
            }
            else
                cout << "Wrong letter! Enter your first word guess: " << endl;
            cin >> wordguess;

            if (wordguess == word & Validwordguess = true) // this is wrong
            {
                cout << "You guessed the word correctly in 1 try! " << endl;
                Gameover = true;
            }

        }

    }


0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 9 more requests to produce the answer.

1 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
Hangman using while and fo loops, if's, and functions.
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • 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...

  • Create a new program, WordGuessingGame. Using a while loop, create a game for the user. The...

    Create a new program, WordGuessingGame. Using a while loop, create a game for the user. The game requires the user to guess a secret word. The game does not end until the user guesses the word. After they win the game, they are prompted to choose to play again. The secret word that user must guess is "valentine". It is a case-sensitive analysis With each guess... If the guess does not have an equal number of characters, tell the user...

  • 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...

  • JAVA Hangman Your game should have a list of at least ten phrases of your choosing.The...

    JAVA Hangman Your game should have a list of at least ten phrases of your choosing.The game chooses a random phrase from the list. This is the phrase the player tries to guess. The phrase is hidden-- all letters are replaced with asterisks. Spaces and punctuation are left unhidden. So if the phrase is "Joe Programmer", the initial partially hidden phrase is: *** ********** The user guesses a letter. All occurrences of the letter in the phrase are replaced in...

  • Convert to use functions where possible #include<iostream> #include<string> using namespace std; int main() {    string...

    Convert to use functions where possible #include<iostream> #include<string> using namespace std; int main() {    string first, last, job;    double hours, wages, net, gross, tax, taxrate = .40;    double oPay, oHours;    int deductions;    // input section    cout << "Enter First Name: ";    cin >> first;    cout << "Enter Last Name: ";    cin >> last;    cin.ignore();    cout << "Enter Job Title: ";    getline(cin, job);    cout << "Enter Hours Worked:...

  • Below are expected output examples: In this assignment you will implement hangman in python. If you...

    Below are expected output examples: In this assignment you will implement hangman in python. If you are not famililar with this game, see the wikipedia article linked above This implementation of hangman will be an interactive command-line interface game. Name the script hangman.py. There will be two players (player 1 and player 2). Player 1 will be responsible for choosing the word for player 2 to guess at the beginning of the game. This is the only time that player...

  • Please help with this Intro to programming in C assignment! Intro to Programming in C-Large Program...

    Please help with this Intro to programming in C assignment! Intro to Programming in C-Large Program 3 - Hangman Game Assignment purpose: User defined functions, character arrays, c style string member functions Write an interactive program that will allow a user to play the game of Hangman. You will need to: e You will use four character arrays: o one for the word to be guessed (solution) o one for the word in progress (starword) o one for all of...

  • Topics c ++ Loops While Statement Description Write a program that will display a desired message...

    Topics c ++ Loops While Statement Description Write a program that will display a desired message the desired number of times. The program will ask the user to supply the message to be displayed. It will also ask the user to supply the number of times the message is to be displayed. It will then display that message the required number of times. Requirements Do this assignment using a While statement.    Testing For submitting, use the data in the...

  • I need my c++ code converted to MASM (assembly language). The instructions below: write an assembly...

    I need my c++ code converted to MASM (assembly language). The instructions below: write an assembly program that does the following; 1. count and display the number of words in the user input string. 2. Flip the case of each character from upper to lower or lower to upper. For example if the user types in:   "Hello thEre. How aRe yOu?" Your output should be: The number of words in the input string is: 5 The output string is : hELLO...

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