作者tsaiminghan (nahgnimiast)
看板C_and_CPP
标题Re: [问题] 小游戏大问题
时间Fri Apr 3 23:20:13 2009
无聊中....
#include <time.h>
#include <stdio.h>
void main()
{
int times;
int win = 0;
int lost = 0;
int input;
int compare;
srand(time(NULL));
printf("几次?\n");
scanf("%d", ×);
times = (times+1)/2;
do
{
compare = rand()%3;
printf("输入剪刀(0), 石头(1), 布(2)\n");
scanf("%d", &input);
if(compare == input)
{
printf("平手\n");
}
else if(compare == (1 + input)%3)
{
printf("输\n");
++lost;
}
else
{
printf("赢\n");
++win;
}
}
while( win<times && lost<times);
if(win==times)
{
printf("这次你赢\n");
}
else
{
printf("这次你输\n");
}
}
--
其实没有要你印出对方出什麽,根本就不用比
rand出来的数字当输赢平手
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 218.168.67.96
※ 编辑: tsaiminghan 来自: 218.168.67.96 (04/03 23:47)