标签:signed rand scan 新人 else srand 导致 循环 null
接4.1,
个人修改后
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int cishu = 0;
int jiage;
int biaozhun;
srand((unsigned) time(NULL));
biaozhun = (rand() * rand()) % 59 + 1;
for( ;biaozhun != jiage; )
{
printf("请输入你猜测的价格");
scanf("%d",&jiage);
if(biaozhun < jiage)
{
printf("猜的高了哦\n");
cishu++;
}
else if(biaozhun > jiage)
{
printf("猜的低了哦\n");
cishu++;
}
else
{
printf("恭喜你猜对了\n");
cishu++;
}
}
printf("一共猜测%d次,价格为%d",cishu,jiage);
return 0;
}
更改历程:修改do-while为for 循环,null前未加time导致数据固定。修改完毕
标签:signed rand scan 新人 else srand 导致 循环 null
原文地址:https://www.cnblogs.com/allsear/p/10151698.html