怎样用c++编石头剪子布啊?

来源:百度知道 编辑:UC知道 时间:2024/06/23 05:38:45
要用到枚举法~别给我c啊,是c++~~~

给,已经编译运行确认:
#include<iostream.h>
#include<time.h>
#include<stdlib.h>

enum Choose
{
stone=1,
scissors,
cloth
};

int a,b;
// a: 用来存放用户的选择
// b: 用来存放电脑的选择

void customer(); // 用来获取用户的合法输入,其值保存在a中
void computer();// 用来获取计算机的输入,其值保存在b中

// 该函数用来获取用户的选择,并保存在a中
void customer()
{
// 获取用户的有效输入
do
{
cout<<"Please enter your choice?(1--stone 2--scissors 3--cloth):"<<endl;
cin>>a;

if(a<stone||a>cloth)
{
cout<<"Your choice is invalid!"<<endl;
}
}while(a<stone||a>cloth);

// 显示用户的选择
if(a==stone)
{
cout<<"Your choice is:stone"<<endl;
}
else if(a==scissors)
{
cout<<"Your choice is:scissors"<<endl;
}