剪刀石头布
#include "stdafx.h"
#include "time.h"
#include "stdlib.h"
//多维数组
//剪刀石头布
int _tmain(int argc, _TCHAR* argv[])
{
//scissor剪刀
//stone石头
//cloth布
char gesture[3][10]={"scissor","stone","cloth"};
int people,computer,result,ret;
while(1){
computer=rand()%3;
printf("input your gesture(0-scissor,1-stone,2-cloth)");
ret=scanf("%d",&people);
if(ret!=1||people<0||people>2)
{printf("输入错误,请输入0,1或2\n");
continue;
}
printf("your gesture:%s\tcomputer's gesture:%s\n",gesture[people],gesture[computer]);
result=(people-computer+4)%3-1;
if(result>0)
printf("You win!\n");
else if(result==0)
printf("Draw!\n");
else
printf("you lose!\n");
}
return 0;
}
结果:
此代码在vs2010中编写