#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; }
【C语言】猜数字游戏
最新推荐文章于 2022-07-09 13:53:07 发布