c++ - 剪刀石头布游戏c++

标签 c++

石头剪刀布游戏 c++ 不显示 cout 来告诉谁赢得了比赛,我不知道出了什么问题,为什么程序不显示 cout。请告诉我出了什么问题、如何解决它以及为什么会发生,我认为 cstdlib 在那里什么也没做。

Objective: To score the rock-paper-scissors game. If the user enters invalid input, your program should say so, otherwise it will output one of the above results.

#include <iostream> 
#include <cstdlib> 

using namespace std; 

int main() 
{ 
    string pone; 
    string ptwo; 
    string r; 
    string p; 
    string s; 

    cout << "Rock, Paper, Scissors Game\n"; 
    cout << "\nPlayer One, please enter your move: ('p' for Paper, 'r' for Rock, 's' for Scissor)";  

    cin >> pone; 

    cout << "\nPlayer Two, please enter your move: ('p' for Paper, 'r' for Rock, 's' for Scissor)"; 

    cin >> ptwo; 

    if (pone == ptwo) 
    { 
        cout <<"\nThere is a tie"<<endl; 
    } 

    if ( pone == r && ptwo == p) 
    { 
        cout << "\nPaper wraps rock, Player 1 win"; 
    } 
    else if (pone == r && ptwo == s) 
    { 
        cout << "\nRock smashes scissors, player 1 win"; 
    } 

    if (pone == p && ptwo == r) 
    { 
        cout <<"\nPaper wraps rock, player 1 win"; 
    } 
    else if ( pone == p && ptwo == s) 
    { 
        cout <<"\nScissors cut paper, player 2 win"; 
    } 

    if ( pone == r && ptwo == p) 
    { 
        cout << "\nPaper wraps rock, Player 1 win"; 
    } 
    else if (pone == r && ptwo == s) 
    { 
        cout << "\nRock smashes scissors, player 1 win"; 
    } 

    if (pone == p && ptwo == r) 
    { 
        cout <<"\nPaper wraps rock, player 1 win"; 
    } 
    else if ( pone == p && ptwo == s) 
    { 
        cout <<"\nScissors cut paper, player 2 win"; 
    } 

    if ( ptwo == s && pone == r) 
    { 
        cout <<"\nScissors cut paper, player 1 win"; 
    } 
    else if (ptwo == s && pone == p) 
    { 
        cout <<"\nRock smashes scissors, player 2 win "; 
    } 

    return 0; 
}

最佳答案

这是你的问题:

if (pone == r && ptwo == p) 
{ 
    cout << "\nPaper wraps rock, Player 1 win"; 
} 
else if (pone == r && ptwo == s) 
{ 
    cout << "\nRock smashes scissors, player 1 win"; 
} 
//etc etc

将“r”、“p”和“s”放在引号中,如下所示:

if (pone == "r" && ptwo == "p")
//etc etc

你应该很好

关于c++ - 剪刀石头布游戏c++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22166766/

相关文章:

c++ - 在 C++ 中返回 vector 标准

c++ - 如何从着色 map 中获取国家数量?

C++ 登录任务计划错误 : No Mapping between account names and security ids was done

c++ - Boost UTF unit_test_main 的命令行参数

c++ - ld.so.1 : protoc: fatal: libstdc++. so.6:在 Solaris 11 中找不到版本 'GLIBCXX_3.4.20'

c# - native 可执行文件中的字符串表资源

c++ - 在通用 lambda 中使用 `if constexpr` 访问成员类型需要两个分支的格式都正确 - gcc 与 clang

c++ - 多态值得增加耦合吗?

c++ - 使用 cout 输出 cerr

c++ - 如何在堆栈上放置新的