10个比较经典的C++程序。初学者就先多学习学习别人吧。
源代码在线查看: 2_40.cpp
#include
using namespace std;
enum Choice {ROCK, CLOTH, SCISS}; //声明枚举类型Choice
enum Winner {Play1, Play2, Tie}; //声明枚举类型Winner
int main()
{ int n;
Choice cho1, cho2;
Winner winner;
cout cout > n; cho1 = Choice(n);
cout > n; cho2 = Choice(n);
if (cho1 == cho2) winner = Tie;
else if (cho1 == ROCK)
if (cho2 == CLOTH) winner = Play2;
else winner = Play1;
else if (cho1 == CLOTH)
if (cho2 == SCISS) winner = Play2;
else winner = Play1;
else
if (cho2 == ROCK) winner = Play2;
else winner = Play1;
if (winner == Tie) cout else if (winner == Play1) cout else cout return 0;
}