c语言猜数字小游戏

  1. #include"stdio.h"
  2. #include"time.h"
  3. #include"stdlib.h"
  4. void play_game()  
  5. {  
  6.     int  fog = 0;  
  7.     int  random = 0;  
  8.       
  9.     random=rand()%101;  
  10.     while(1)  
  11.     {  
  12.         printf("请输入一个数:");  
  13.         scanf("%d",&fog);  
  14.   
  15.     if(random==fog)  
  16.     {  
  17.         printf("恭喜你,答对了\n");  
  18.         break;  
  19.     }  
  20.     else if (fog>random)  
  21.     {  
  22.         printf("你输入的大了\n");  
  23.     }  
  24.     else  
  25.     {  
  26.         printf("你输入的小了\n");  
  27.     }  
  28.     }  
  29.   
  30. }  
  31. int main()  
  32. {  
  33.     int input;  
  34.     srand((unsigned )time(NULL));  
  35.     do  
  36.     {  
  37.         menu();  
  38.         printf("请输入你的选择:");  
  39.         scanf("%d",&input);  
  40.         switch(1)  
  41.         {  
  42.         case 1:  
  43.           play_game();  
  44.           break;  
  45.         case 0:  
  46.             exit(EXIT_SUCCESS);  
  47.         default:  
  48.             printf("error");  
  49.             break;  
  50.         }  
  51.     }while(input);  
  52.     system("pause");
  53.     return 0;            
  54. }  

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值