C++ 我的刽子手作品不会按正确的顺序印刷

C++ 我的刽子手作品不会按正确的顺序印刷,c++,C++,我不懂编码,但我能为刽子手找到一个编码。我很确定我的编码方式是多余的,但我真正的问题是,代码不会在正确的时间打印正确的图片,就像他们有一定数量的错误猜测某张图片应该打印一样 #include <iostream> using namespace std; int main() { beginning: int num_guesses = 6; string word; string guess; s

我不懂编码,但我能为刽子手找到一个编码。我很确定我的编码方式是多余的,但我真正的问题是,代码不会在正确的时间打印正确的图片,就像他们有一定数量的错误猜测某张图片应该打印一样


#include <iostream>
using namespace std;

int main() 
{
        beginning:
        int num_guesses = 6;
        string word;
        string guess;
        string player1, player2;

        cout << "Hello! Welcome to Hangman! \n";
        cout << "PLAYER 1, Please Enter Your Name: \n"; 
        cin >> player1;
        cout << player1 << ", Please input a word for Player 2 to guess" << endl;//PLAYER 1 inputs the word to be guessed
        cin >> word;    

        cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
        cout << "PLAYER 2, Please Enter Your Name: \n"; //PLAYER 2 will be attempting to guess PLAYER 1's word
        cin >> player2;

        string hidden_word(word.length(),'~');//User word will be replaced by ~
        cout << hidden_word << endl;

        cout << " ________   " << endl;//This is the beginning statement that includes that state of the hangman.
        cout << " |       |  " << endl;
        cout << " |          " << endl;
        cout << " |          " << endl;
        cout << " |          " << endl;
        cout << " |          " << endl;
        cout << "------------" << endl; 
        cout << "" << endl;
        cout << "There are " << hidden_word.length() << " letters ";
        cout << player2 << ", you have " << num_guesses << " tries left" << endl;

        // This loop will execute while the number of guesses is greater than 0.
        // The ~ variable doesn't store the word
        while (num_guesses > 0 && hidden_word != word) 
        {
            cout << hidden_word << endl;
            cout << num_guesses << " incorrect guesses left. " << endl;
            cout << "Guess: ";
            cin >> guess;

            // Determines if the guess is more than one character.
            if (guess.length() > 1) 
            {
                cout << "That is more than one character.";
                cout << "" << endl;
            }

            // Determines if the guess is a lowercase letter.
            else if (guess[0] > 'z' || guess[0] < 'a') 
            {
                cout << "Your guess must be a lowercase letter. " << endl;
                cout << "" << endl;
            }

            // First, the program finds the guess in the word. If it is found, the ~ at which PLayer2 guess occurs will be replaced with Player2 guess. Otherwise, the number of guesses will decrement by 1.
            else 
            {
                size_t index_found = word.find(guess);
                if (index_found != string::npos) 
                {
                    for (int i = 0; i < word.length(); i++) 
                    {
                        if (word[i] == guess[0]) 
                        {
                            hidden_word[i] = guess[0];
                        }
                    }
                    cout << "Correct!" << endl;
                    cout << "" << endl;
                    int pic = num_guesses;  
                    if (pic == 6)
                    {
                        cout << " ________   " << endl;
                        cout << " |       |  " << endl;
                        cout << " |          " << endl;
                        cout << " |          " << endl;
                        cout << " |          " << endl;
                        cout << " |          " << endl;
                        cout << "------------" << endl; 
                    }
                    else if (pic == 5)
                    {
                        cout << " ________   " << endl;
                        cout << " |       |  " << endl;
                        cout << " |       0  " << endl;
                        cout << " |          " << endl;
                        cout << " |          " << endl;
                        cout << " |          " << endl;
                        cout << "------------" << endl; 
                    }
                    else if (pic == 4)
                    {
                        cout << " ________   " << endl;
                        cout << " |       |  " << endl;
                        cout << " |       0  " << endl;
                        cout << " |       |  " << endl;
                        cout << " |          " << endl;
                        cout << " |          " << endl;
                        cout << "------------" << endl;
                    }
                    else if (pic == 3)
                    {
                        cout << " ________   " << endl;
                        cout << " |       |  " << endl;
                        cout << " |       0  " << endl;
                        cout << " |      /|  " << endl;
                        cout << " |          " << endl;
                        cout << " |          " << endl;
                        cout << "------------" << endl;
                    }
                    else if (pic == 2)
                    {
                        cout << " ________   " << endl;
                        cout << " |       |  " << endl;
                        cout << " |       0  " << endl;
                        cout << " |      /|\ " << endl;
                        cout << " |          " << endl;
                        cout << " |          " << endl;
                        cout << "------------" << endl;
                    }
                    else if (pic == 1)
                    {
                        cout << " ________   " << endl;
                        cout << " |       |  " << endl;
                        cout << " |       0  " << endl;
                        cout << " |      /|\ " << endl;
                        cout << " |      /   " << endl;
                        cout << " |          " << endl;
                        cout << "------------" << endl;
                    }
                    else if (pic == 0)
                    {
                        cout << " ________   " << endl;
                        cout << " |       |  " << endl;
                        cout << " |       0  " << endl;
                        cout << " |      /|\ " << endl;
                        cout << " |      / \ " << endl;
                        cout << " |          " << endl;
                        cout << "------------" << endl;
                    }   
                } 
                else 
                {
                    cout << "Incorrect!" << endl;
                    cout << "" << endl;
                    num_guesses = num_guesses - 1;
                    int pic = num_guesses;  
                    if (pic == 6)
                    {
                        cout << " ________   " << endl;
                        cout << " |       |  " << endl;
                        cout << " |          " << endl;
                        cout << " |          " << endl;
                        cout << " |          " << endl;
                        cout << " |          " << endl;
                        cout << "------------" << endl; 
                    }
                    else if (pic == 5)
                    {
                        cout << " ________   " << endl;
                        cout << " |       |  " << endl;
                        cout << " |       0  " << endl;
                        cout << " |          " << endl;
                        cout << " |          " << endl;
                        cout << " |          " << endl;
                        cout << "------------" << endl; 
                    }
                    else if (pic == 4)
                    {
                        cout << " ________   " << endl;
                        cout << " |       |  " << endl;
                        cout << " |       0  " << endl;
                        cout << " |       |  " << endl;
                        cout << " |          " << endl;
                        cout << " |          " << endl;
                        cout << "------------" << endl;
                    }
                    else if (pic == 3)
                    {
                        cout << " ________   " << endl;
                        cout << " |       |  " << endl;
                        cout << " |       0  " << endl;
                        cout << " |      /|  " << endl;
                        cout << " |          " << endl;
                        cout << " |          " << endl;
                        cout << "------------" << endl;
                    }
                    else if (pic == 2)
                    {
                        cout << " ________   " << endl;
                        cout << " |       |  " << endl;
                        cout << " |       0  " << endl;
                        cout << " |      /|\ " << endl;
                        cout << " |          " << endl;
                        cout << " |          " << endl;
                        cout << "------------" << endl;
                    }
                    else if (pic == 1)
                    {
                        cout << " ________   " << endl;
                        cout << " |       |  " << endl;
                        cout << " |       0  " << endl;
                        cout << " |      /|\ " << endl;
                        cout << " |      /   " << endl;
                        cout << " |          " << endl;
                        cout << "------------" << endl;
                    }
                    else if (pic == 0)
                    {
                        cout << " ________   " << endl;
                        cout << " |       |  " << endl;
                        cout << " |       0  " << endl;
                        cout << " |      /|\ " << endl;
                        cout << " |      / \ " << endl;
                        cout << " |          " << endl;
                        cout << "------------" << endl;
                    }
                }
            }
        }

        // Determines whether the player lost or won. User word will be printed win or lose and the users will be asked if they want to play again.
        if (hidden_word == word) 
        {
            string answer;
            cout << "You win!" << endl;
            cout << "The word was: " << word << endl;
            cout << "Do you wish to play again? Y/N" << endl;
            cin >> answer;
            if (answer == "Y" || answer == "y")
            {
                goto beginning;
            }
            else
            {
                return 0;
            }
        } 
        else 
        {
            string answer;
            cout << "You lose." << endl;
            cout << "The word was: " << word << endl;
            cout << "Do you wish to play again? Y/N" << endl;
            cin >> answer;
            if (answer == "y" || answer == "Y")
            {
                goto beginning;
            }
            else
            {
                return 0;
            }
        }
}

#包括
使用名称空间std;
int main()
{
开始:
int num_猜测=6;
字符串字;
字符串猜测;
弦乐演奏者1,演奏者2;
cout player1;
cout 0&&hidden_单词!=单词)
{
第213行的cout变化

else (pic == 0);


使用一些函数,我可以将您的程序缩短到190行。请看代码以及我选择如何打印绞刑架。以下是代码:

#包括//std::cout、std::cin、std::endl
#include//std::string
#include//std::无序_集
//您不应该使用此选项,但它将使代码更易于在此处执行
使用名称空间std;
/**
让玩家1输入一个单词让玩家2猜
@返回播放器1输入的单词
*/
字符串getWord();
/**
打印刽子手的照片
@param Error_猜测错误猜测的次数
*/
无效打印(未签名整数错误猜测);
/**
清除控制台(特定于操作系统)
*/
无效清除屏幕();
int main()
{
无符号整数错误猜测;
字符串猜测;
字符串隐藏字;
无序的拼音字母;
bool play再次=真;
做
{//“再次播放”循环
//开始新游戏,所以重置变量
错误的猜测=0;
猜猜看。清楚();
隐藏的单词=getWord();
猜字母。清除();
bool first_loop=true;
while(猜!=隐藏的单词&猜错猜;
if(猜测字母.查找(猜测)!=猜测字母.结束())
{//Player猜到了他们已经拥有的东西
库特

你真的不应该在代码中使用goto。与其使用
\
不如使用
\\
这太棒了。我知道有一种方法可以缩短我的代码,尤其是图片,但我还没有学会。我特别欣赏防止重复猜测的部分。这非常有用,谢谢。
else if(pic == 0)