一个猜测程序 用户心里选择一个数 让计算机询问用户是否正确并做控制 知道猜对数字(图)

来源:互联网 发布:烧香拜佛软件 编辑:程序博客网 时间:2024/05/18 03:19
#include "stdAfx.h"#include "ctype.h"#include "stdlib.h"int main(void){int big(int max,int sum);int small(int max,int sum);char ch;int ave=50,sum=0,max;printf("The beginning Need little according to need big 'X' as 'D' if guess it please click 'Y'\n");printf("%d?\n",ave);while((ch=getchar())!=EOF){if(ch!='\n'){switch(ch){case 'y':printf("Done! please press CTRL + Z exit\n");break;case 'd':printf("Need big? good\n");printf("%d?\n",big(ave,sum));ave=big(ave,sum);break;case 'x':printf("Need small? good\n");printf("%d?\n",small(ave,sum));ave=small(ave,sum);break;}}}system("pause");return 0;}int big(int max,int sum){sum=(max+(max+50))/2;return sum;}int small(int max,int sum){sum=(max+(max-25))/2;return sum;}

原创粉丝点击