猜数游戏程序

  • b2_300632
    了解作者
  • 839B
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-04-11 01:41
    上传日期
C语言编写的猜数游戏程序,供交流使用。
list.rar
  • list
  • caisuyouxi.c
    1.4KB
内容介绍
/*猜数游戏*/ #include "stdio.h" /**/ #include "stdlib.h" /*调用random函数和randomize函数*/ #include "ctype.h" /*调用toupper函数*/ main() { int count, /*猜测次数*/ number,/*随机被猜数*/ guess; /*所猜测数字*/ char yes='Y'; printf("\nNow let us play the game.\n Guess the number:"); while(toupper(yes) == 'Y') { count = 0; randomize(); number = random(100) + 1;/*产生随机数*/ do { do { printf("\nInput an integer number(1-100):"); scanf("%d",&guess); }while(!(guess>=1&&guess<=100)); if(guess<number) printf("\nYour answer is LOW,try again."); if(guess>number) printf("\nYour answer is HIGH,try angin.");/*交互信息*/ count++; if(count == 15) { printf("\nThis is the %d times! Think it hard next!"); exit(0);/*15次退出*/ } }while(!(guess==number));/*等值判断*/ if(count<=7) { printf("\nYou have got it in %d times.\n",count); printf("\nCongretulations!"); } else { printf("\nYou got it in %d times.\n",count); printf("\nI bet you can do it better."); } printf("\nNEXT?(Y/N):"); /*重新游戏*/ scanf("%s",&yes); /*scanf("%c",&yes);用此格式则出错,必须在%号前面留一个空格*/ } }
评论
    相关推荐