石头剪刀布c++代码
直接看吧:

#include <iostream>
#include <cstdlib>
#include <ctime>
#define random(a,b) (rand()%(b-a)+a)
int check(int x,int y);
using namespace std;
int main(void)
{
int i,j,x;
//int i;
srand((int)time(0));
cout<<"欢迎来到石头剪刀布游戏"<<endl<<"规则不讲了"<<endl<<"直接开始!"<<endl;
cout<<"0石头,1剪刀,2布"<<endl;
cin>>i;
while(i<=-1||i>=3)
{
cout<<"error"<<endl;
cin>>i;
}
j=random(0,3);
cout<<"ai出" <<j<<endl;
if (check(i,j)==0)
{
cout<<"平局!"<<endl;
}
else if(check(i,j)==1)
{
cout<<"胜利!"<<endl;
}
else
{
cout<<"失败!"<<endl;
}
cout<<"感谢游玩!输入任何以退出。"<<endl;
cin>>x;
exit(0);
}
int check(int a,int b)
{
if(a-b==0)
return 0;
if(a-b==-1||a-b==2)
return 1;
if(a-b==1||a-b==-2)
return 2;
}

好了,本专栏到此结束。