1 #include
2 #include
3 #include
4 int main(void)
5 {
6 char gesture[3][10]={"scissor","stone","cloth"};
7 int man,computer,result,ret;
8
9 srand(time(NULL));
10 while(1){
11 computer=rand()%3;
12 printf("\ninput your gesture (0_scissor 1-stone 2-cloth):\n");
13 ret=scanf("%d",&man);
14 if(ret!=1||man<0||man>2){
15 printf("invalid input!\n");
16 return 1;
17 }
18 printf("your gesture:%s\tcomputer's gesture:%s\n",gesture[man], gesture[computer]);
19 result=(man-computer+4)%3-1;
20 if(result>0)
21 printf("you win!\n");
22 else if(result==0)
23 printf("draw!\n");
24 else
25 printf("you lose!\n");
26 }
27 return 0;
28 }
result=(man-computer+4)%3-1;用来比较大小的,而且还能循环。。。。。此程序的关键所在
阅读(622) | 评论(0) | 转发(0) |