trouble with loops, functions, and organization´

  c++, for-loop, function, if-statement, while-loop

and 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 only. loop until they enter 1 letter
        {
            cout << endl << "Type a single letter and press <enter>: ";
            cin >> letterguess;   // enter letter guess          

            for (int i = 0; i < letterguess.length(); i++) //ignore case of letter guess
            {
                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)
            {
                cout << "You guessed the word correctly in 1 try! " << endl;
                Gameover = true;

            }

        }
      

    }   
       
        

        
        
    }

Source: Windows Questions C++

LEAVE A COMMENT