C语言编程:剪刀石头布的小游戏

希望是自己编的,不是在电脑上复制的啊,还有最好可以有注释,可以让初学者看得懂啊,希望能有高手帮忙啊,万分感激啊!!!!
最好是编译过了,没有错误啊!!!

原创:
TC2.0以及gcc 编译通过

/*=======================================================
*Author :wacs5
*Date :20100601(YYYYMMDD)
*Function :剪刀石头布
*=======================================================*/
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <time.h>

int main()
{
char name[4][15]={"","scissors","stone","cloth"};
int x[2];
int i;

srand(time(NULL));
for (i=0;i<10;i++) /*10 times game*/
{
x[0]=1+rand()%3; /*generate a number from 1 to 3*/
x[1]=1+rand()%3; /*generate another number from 1 to 3*/
printf("A=%-12sB=%-12s\t",name[x[0]],name[x[1]]);
if (x[0]==x[1])
printf("draw\n"); /*和*/
else if (x[0]%3+1==x[1]) /*lost*/
printf("lost\n");
else /*win*/
printf("win\n");
}

getch();
return 0;
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2019-02-10
石头
剪子

A出
B出
a石头遇b剪子
a赢
a剪子遇b布
a赢
a布遇b石头
a赢
b石头遇a剪子
b赢
b剪子遇a布
b赢
b布遇a石头
b赢
若相同
则平局
第2个回答  2010-06-01
#include <stdio.h>
#include <time.h>
#include <stdlib.h>

const char* gits(int i)
{
switch(i)
{
case 0:
return "石头";
case 1:
return "剪子";
default:
return "布 ";
}
}

int main()
{
time_t t = time(NULL);
srand((unsigned int)t);
while(1)
{
int a = rand()%3;
int b = rand()%3;

printf("A: %s, B: %s", gits(a), gits(b));
if (
(a==0&&b==1)||
(a==1&&b==3)||
(a==3&&b==0)
)
{
printf("\tA 赢了\n");
system("pause");
continue;
}

if (
(b==0&&a==1)||
(b==1&&a==3)||
(b==3&&a==0)
)
{
printf("\tB 赢了\n");
system("pause");
continue;
}

printf("\t 持平了\n");
system("pause");
continue;
}
system("pause");
return 0;
}