码迷,mamicode.com
首页 > 编程语言 > 详细

用C语言编写的简单的猜数字游戏

时间:2015-09-23 01:23:38      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:include   screen   ffffff   c语言   公开赛   

#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main()
{
          int random = 0;
          int input = 0;
          int start = 1;
          while (start)
             {
                   printf("*********************\n");
                   printf("**1 start    0.exit**\n");
                   printf("*********************\n");
                   printf("请选择:>");
                   scanf("%d", &start);
                   switch (start)
                        {
                               case 1:
                                 {
                                      srand((unsigned)time(NULL));
                                      random = rand()%100;
                                      while (1)
                                            {
                                                   printf("请输入你猜的数:>");
                                                   scanf("%d", &input);
                                                   if (input > random)
                                                          {
                                                                printf("猜大了\n");
                                                           }
                                                    else if (input < random)
                                                           {
                                                                 printf("猜的太小了\n");
                                                            }
                                                     else
                                                           {
                                                                 printf("你好厉害啊\n");
                                                                   break;
                                                             }
                                     }
                                            break;
                            }
                              case 0:
                                {
                                      printf("感谢使用猜数字游戏,bye bye\n");
                                         exit(0);
                                      break;
                                 }
                             default:

                                 {
                                 break;
                                 }       
                      }
                       return 0;
}

用C语言编写的简单的猜数字游戏

标签:include   screen   ffffff   c语言   公开赛   

原文地址:http://10706198.blog.51cto.com/10696198/1697250

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!