#include
#include
#include
int main(void)
{
int rst,g;
int guesscount;
//用随机函数了
srand( time(NULL) );
printf("猜数游戏,输入-1退出.\r\nLet's go !\r\n\r\n");
do
{
//生成随机数
rst = (int)((double) rand() /(double) RAND_MAX * 100);
//重置猜的次数
guesscount = 0;
while( 1 )
{
guesscount++;
printf("猜猜是几:");
scanf("%d",&g);
if( g==-1) //如果输入的玩家数为-1,退出程序
return 0;
if(g == rst )
{
printf("恭喜,只用%d次就猜对了。\r\n再来一把!\r\n",guesscount);
break;
}
else
{
if (guesscount < 10 )
printf("%s了,再",g > rst ? "大":"小" );
else
{
printf("看来你猜不出来了,试试下一个。\r\n");
break;
}
}
}
} while(1);
return 0;
};
#include
#include
#include
int main()
{
int i,randomnum,yourguess;
randomize();
randomnum=random(101);
printf("请猜一个1-100间的数:\n");
for(i=1;i<=10;i++)
{
scanf( "%d",&yourguess);
if(yourguess==randomnum)
{
printf("这是第%d次猜数,恭喜猜对了!\n\n",i);
printf("按任意键退出\n",i);
getch();
break;
}
else if(yourguess
if(i<10)
{
printf("这是第%d次猜数,猜小了! 还剩%d次机会,请继续...\n",i,10-i);
continue;
}
else
printf("这是最后一次猜数,猜小了! 很遗憾...\n");
}
else if(yourguess>randomnum)
{
if(i<10)
{
printf("这是第%d次猜数,猜大了! 还剩%d次机会,请继续...\n",i,10-i);
continue;
}
else
printf("这是最后一次猜数,猜大了! 很遗憾...\n");
}
}
return 0;
}