源代码如下:
#include<stdio.h>
#include<stdlib.h>
#include<time.h>//生成随机函数起点时用到time.h
int main()
{
int number1 = 0, choice = 0, number2 = 0;
printf("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
");//界面设置
printf("$$$$$ 欢 迎 来 到 $$$$$
");
printf("$$$$$ 猜 数 字 游 戏 $$$$$
");
printf("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
");
printf(" 1.进入游戏
");
printf(" 2.退出游戏
");
scanf("%d", &choice);
srand((unsigned int)time(NULL));//设置随机数起点
while (choice == 1)
{
printf("请输入所猜的数:
");
scanf("%d", &number2);
number1 = rand() % 100;
while (1)
{
if (number2 == number1)
{
printf("666 恭喜你答对了!");
printf("
1.再玩一次
2.退出游戏
");
scanf("%d", &number2);
if (number2 == 1)
break;
if (number2 == 2)
return 0;
}
if (number2 < number1)
{
printf("
猜小了!
");
scanf("%d", &number2);
}
if (number2 > number1)
{
printf("
猜大了!
");
scanf("%d", &number2);
}
}
}
while(choice == 2)
{
return 0;
}
system("pause");
return 0;
}
运行结果: