源代码如下:
#include<stdio.h>
#include<stdlib.h>
#include<time.h>//生成随机函数起点时用到time.h
int main()
{
int number1 = 0, choice = 0, number2 = 0;
printf("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");//界面设置
printf("$$$$$ 欢 迎 来 到 $$$$$\n");
printf("$$$$$ 猜 数 字 游 戏 $$$$$\n");
printf("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");
printf(" 1.进入游戏\n");
printf(" 2.退出游戏\n");
scanf("%d", &choice);
srand((unsigned int)time(NULL));//设置随机数起点
while (choice == 1)
{
printf("请输入所猜的数:\n");
scanf("%d", &number2);
number1 = rand() % 100;
while (1)
{
if (number2 == number1)
{
printf("666 恭喜你答对了!");
printf("\n1.再玩一次\n2.退出游戏\n");
scanf("%d", &number2);
if (number2 == 1)
break;
if (number2 == 2)
return 0;
}
if (number2 < number1)
{
printf("\n猜小了!\n");
scanf("%d", &number2);
}
if (number2 > number1)
{
printf("\n猜大了!\n");
scanf("%d", &number2);
}
}
}
while(choice == 2)
{
return 0;
}
system("pause");
return 0;
}
运行结果:
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。