“岩石,剪刀,剪刀”的C ++代码问题

问题描述 投票:1回答:1

我知道有多种方法可以为“岩石,纸张,剪刀”游戏编写代码。但是我尝试根据我的C ++基本知识编写以下代码。

using std::cin;
using std::cout;
using std::endl;
int main(int argc, char** argv) {
    enum object {rock, paper, scissors}
    object player1, player2;
    cout <<"Enter two objetcs (objects include rock, paper or scissors):";
    cin >>player1 >> player2;
    if (player1==player2) cout <<"objects are equal";
    else if (player1==rock && player2=paper cout << "player 2 is the winner";
    else if (player1==rock && player2=scissors cout<<"player 1 is the winner";
    else if (player1==paper && player2=rock) cout << "player 1 is the winner";
    else if (player1==paper && player2=scissors) cout <<"Palyer 2 is the winnder";
    else if (player1==scissors && player2=paper) cout << "Player 1 is winner";
    else cout <<"Player 2 is the winner";

}

编译器(Dev-C++)cin >>player1 >> player2;行中发现错误,解释了"In Function 'int main(int, char**): [error] expected initializer before 'player1'"。我没有得到这个警告的意思。任何人都可以解释该错误的含义以及如何纠正该错误吗?

c++
1个回答
0
投票
enum object {rock, paper, scissors}

缺少分号(;)

© www.soinside.com 2019 - 2024. All rights reserved.