初阶c语言的小程序;
如有错误,请您赐教qwq
#include
#include
int main()
{
int select = 1;
int result;
while(select)
{
printf("********************************\n");
printf("* [1] play *\n");
printf("* [0] exit *\n");
printf("********************************\n");
printf("请选择:>");
scanf("%d", &select);
if(select == 0)
break;
if(select != 1)
{
printf("输入有误,请重新输入.....\n");
continue;
}
///
//1、产生一个随机数 (1 ~ 100)
srand(time(NULL)); //设置随机种子,用time可以保证每次运行的随机数都是不同的。
int ans = rand() % 100 + 1;
while(1)
{
printf("请输入答案:>");
scanf("%d", &result);
if(result > ans)
{
printf("数字大了.\n");
}
else if(result < ans)
{
printf("数字小了.\n");
}
else if(result == ans)
{
printf("恭喜你,猜对了......\n");
system("pause");
break;
}
}
///
}
printf("GoodBye.....\n");
return 0;
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)