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

[置顶] 【C语言】 猜数字游戏

2016-05-26 12:23 405 查看
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

void game()
{
int input = 0;
printf("欢迎使用猜数字游戏\n");
srand((unsigned int)time(NULL));
int ret = rand() % 100;
do
{
printf("请输入你猜的数字:>");
scanf_s("%d", &input);
if (input > ret)
{
printf("您猜得太大了\n");
}
else if (input < ret)
{
printf("您猜得太小了\n");
}
else
{
printf("恭喜你猜对了\n");
break;
}
} while (1);
}

void menu()
{
printf("************************\n");
printf("**** 1.开始游戏 ********\n");
printf("**** 0.退出游戏 ********\n");
printf("************************\n");
}
int main()
{
int choice = 1;
while (choice)
{
menu();
printf("请选择:>");
scanf_s("%d", &choice);
switch (choice)
{
case 1:
game();
break;
default:
break;
}
}

system("pause");
return 0;
}


本文出自 “Vs吕小布” 博客,请务必保留此出处http://survive.blog.51cto.com/10728490/1702474
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: