#include <stdio.h>
#include <math.h>
#include <stdlib.h>
void main()
{
int user,computer;
int usercount=0,computercount=0;
char count;
printf("---------------------------------\n");
printf("------------人机猜拳-------------\n");
printf("---------------------------------\n");
printf("0代表剪刀,1代表石头,2代表布\n");
srand((unsigned)time(NULL));
computer=rand()%3;
do
{
printf("\n请输入:");
scanf("%d",&user);
if(user==0&&computer==2||user==1&&computer==0||user==2&&computer==1)
{
printf("恭喜你获胜");
usercount++;
}else if(user==computer)
{
printf("平局");
}else if(user>2)
{
printf("你输入的数字不正确");
} else
{
printf("失败");
computercount++;
}
printf("是否继续?继续请摁y,其他结束\n");
fflush(stdin);
scanf("%c",&count);
}while(count=='y');
printf("你赢了%d次,电脑赢了%d次\n",usercount,computercount);
if(usercount>computercount)
{
printf("恭喜你获得了最后胜利\n");
}else if(usercount==computercount)
{
printf("平局,继续努力\n");
}else
{
printf("你被电脑战胜,下次加油\n");
}
}