猜数字游戏

xiaoxiao2025-11-26  6

#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #include <time.h> void menu() {     printf("************************\n");     printf("******  1. play  *******\n");     printf("******  0. exit  *******\n");     printf("************************\n");

} void game() {     int num = 0;     int set = rand()%100+1;     while (1)     {         printf("请输入猜的数字");             scanf("%d", &num);             if (num == set)             {                 printf("恭喜你,猜对了");                 break;             }             else if (num > set)             {                 printf("猜大了");             } else {     printf("猜小了"); }

    }

} int main() {     int input = 0;     srand((unsigned ) time (NULL));     do     {         menu();         printf("请选择");         scanf("%d", &input);         switch (input)         {         case 1:             game();             break;         case 0:             printf("退出游戏");                 break;         default:             printf("输入有误,请重新输入");                 break;         }     } while (input);     system("pause");     return 0;     }  

转载请注明原文地址: https://www.6miu.com/read-5040057.html

最新回复(0)