您的位置:首页 > 编程语言 > C语言/C++

【C语言】猜数字游戏

2017-03-30 21:13 246 查看
#include<stdio.h>
#include<time.h.>
#include<stdlib.h>
void menu()
{
printf("*******************\n");
printf("***1.play 0.exit***\n");
printf("*******************\n");
}
void play_game()
{
int rand_num = rand() % 100;
int tmp = 0;
while (1)
{
printf("请输入你猜的数字:");
scanf("%d", &tmp);
if (tmp == rand_num)
{
printf("猜对了\n");
break;
}
else if (tmp > rand_num)
{
printf("猜大了\n");
}
else
{
printf("猜小了\n");
}
}
}
int main()
{
int input = 0;
srand((unsigned int)time(NULL));
do
{
menu();
printf("请选择:");
scanf("%d", &input);
switch (input)
{
case 1:
play_game();
break;
case 0:
exit(EXIT_SUCCESS);
break;
default:
printf("选择错误.\n");
break;
}
} while (input);
system("pause");
return 0;
}






                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: