您的位置:首页 > 其它

一个简单的猜数字游戏

2016-03-27 20:15 344 查看
猜数字游戏

#include<stdio.h>

#include<stdlib.h>

#include<time.h>

void play_game()

{

srand((unsigned)time(NULL));

int ret = rand() % 101;

int input = 0;

while (1)

{

printf("请猜数字:");

scanf_s("%d", &input);

if (input < ret)

{

printf("猜小了!\n");

}

else if (input > ret)

{

printf("猜大了!\n");

}

else

{

printf("恭喜你,猜对了!\n");

break;

}

}

printf("%d\n", ret);

}

void menu()

{

printf("1.开始游戏 0.退出游戏\n");

}

int main()

{

int choice = 1;

while (choice)

{

menu();

printf("请选择:");

scanf_s("%d", &choice);

switch (choice)

{

case 1:

play_game();

break;

case 0:

break;

}

}

system("pause");

return 0;

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