猜数游戏程序

//均已调试通过,编译器为DEV C++
//猜数游戏程序 01-10-07 17:46
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <conio.h>
int main()
{    
      int num,r,i=0;
      char ch;
      Start:
        i=0;   
      srand((unsigned )time(NULL));   //给srand()提供一个种子 。
     
      r=rand()%1000+1;                 //取余产生1--1000的随机数。
      printf("%d/n",r);
      printf("I have a number between 1 and 1000,Can you guess the number?/n");
         Begin:
                printf("you  have %d time !",10-i);   //提示剩余次数
                printf(" please type you  guess :/n");
                  i++; 
                  if(scanf("%d",&num)!=1)  //利用scanf()的返回值,若输入整型返回1,否则返回0
                    {
                     fflush(stdin);         //清空键盘输入缓冲区 ,包括上次输入的回车
                                       //在接受前最好先清除缓冲区    
                    printf("Error,please input num between 1--1000./n");
                   goto Begin;
                    }
                if(num<=1||num>=1000)
                   {
                       printf("Error,please input num between 1--1000./n");
                   goto Begin;
                   }
                if(i>=10)                         
                     {
                        printf("Too bad!!!Bye bye./n");
                        goto End;
                     }
              else  if(num==r)
                   {
                        printf("Excellent!You guessed the number!/n");
                       printf("Would you like to play again(y or n)?/n");
                        fflush(stdin);                       //清除键盘缓冲区的内容
                   if(  ( ch=getchar())=='y')         //注意不同的引号 ,接受字母的方法 以及表示格式
                         //  if(ch=='y')
                             goto Start;
                      else  if(ch=='n')
                             goto End;    
                  }
               else if(num<r)
                   {
                         printf("Too low,Try again./n");
                         goto Begin;
                   }
                 else if(num>r)
                    {
                        printf("Too high,T0ry again./n");
                        goto Begin;
                    } 
               End:
              return 0;
}   
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值