c语言高手看下,谢谢急用~~~

#include <time.h>
#include <stdio.h>
#include <stdlib.h>
int t;
time_t ts,te,d;
main()
{ int n,k=0;
char h;
extern time_t te,ts,d;
extern int t;
void fairy(int m);
void jishi(time_t a);
do
{ ts=time(NULL);
srand((unsigned)time(NULL));
t=rand()%100;
printf("input a number:");
scanf("%d",&n);
fairy(n);
printf("\nif you want to continue this game please enter c:");
scanf("%c",&h);
if(h=='c')
k=1;
else k=0;
}while(k==1);
printf("end");
}
void fairy(int m)
{ extern int t;
time_t ts,te,d;
int r;
void jishi(time_t a);
if(m>t)
{ printf("your number is bigger than t");
printf(" please input another number:");
scanf("%d",&r);
fairy(r);
}
if(m<t)
{ printf("your number is smaller than t");
printf(" please input another number:");
scanf("%d",&r);
fairy(r);
}
if(m==t)
{ extern time_t ts,te,d;
te=time(NULL);
d=te-ts;
printf(" your are right,congratuations to you!");
jishi(d);
}
}
void jishi(time_t a)
{ if(a>=0&&a<10)
printf("\nperfect! your time is %ld seconds",a);
if(a>=10&&a<60)
printf("\nso so.your time is %ld seconds",a);
if(a>=60)
printf("\noh shit! your time is %ld seconds",a);
}
这个程序在运行的过程中,会自动跳过printf("\nif you want to continue this game please enter c:");
scanf("%c",&h);
if(h=='c')
k=1;
else k=0;
}while(k==1);
printf("end");
中的scanf语句,这是为什么呢?怎样解决呢?急用,最好今天解决,谢谢!好的话会追加悬赏答谢的

你在这一小段语句前已经有个scanf语句了,因此系统自动将你前面的那次输入所按的回车算作这一次的字符了,因为回车符也算是一个字符,在ASCII码中表示是10或者13.这样的话就会自动跳过输入。
你可以在这个scanf语句之前加一个getch();语句“吃掉”这个回车符。这个语句包含在conio.h头文件中。所以要先#include <conio.h>
温馨提示:内容为网友见解,仅供参考
第1个回答  2007-09-07
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
int t;
time_t ts,te,d;
int main()
{ int n,k=0;
char h;
extern time_t te,ts,d;
extern int t;
void fairy(int m);
void jishi(time_t a);
do
{ ts=time(NULL);
srand((unsigned)time(NULL));
t=rand()%100;
printf("input a number:");
scanf("%d",&n);
fairy(n);
printf("\nif you want to continue this game please enter c:");
scanf("%s",&h);
if(h=='c')
k=1;
else k=0;
}while(k==1);
printf("end");
return 0;
}
void fairy(int m)
{ extern int t;
//time_t ts,te,d;
int r;
void jishi(time_t a);
if(m>t)
{ printf("your number is bigger than t");
printf(" please input another number:");
scanf("%d",&r);
fairy(r);
}
if(m<t)
{ printf("your number is smaller than t");
printf(" please input another number:");
scanf("%d",&r);
fairy(r);
}
if(m==t)
{ extern time_t ts,te,d;
te=time(NULL);
d=te-ts;
printf(" your are right,congratuations to you!");
jishi(d);
}
}
void jishi(time_t a)
{ if(a>=0&&a<10)
printf("\nperfect! your time is %ld seconds",a);
if(a>=10&&a<60)
printf("\nso so.your time is %ld seconds",a);
if(a>=60)
printf("\noh shit! your time is %ld seconds",a);
}
第2个回答  2007-09-07
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
int t;
time_t ts,te,d;
main()
{ int n,k=0;
char h;
extern time_t te,ts,d;
extern int t;
void fairy(int m);
void jishi(time_t a);
do
{ ts=time(NULL);
srand((unsigned)time(NULL));
t=rand()%100;
printf("input a number:");
scanf("%d",&n);
fairy(n);
printf("\nif you want to continue this game please enter c:");
fflush(stdin); //用这个语句清除缓存中信息
scanf("%c",&h);
if(h=='c')
k=1;
else k=0;
}while(k==1);
printf("end");
}

void fairy(int m)
{ extern int t;
time_t ts,te,d;
int r;
void jishi(time_t a);
if(m>t)
{ printf("your number is bigger than t");
printf(" please input another number:");
scanf("%d",&r);
fairy(r);
}
if(m<t)
{ printf("your number is smaller than t");
printf(" please input another number:");
scanf("%d",&r);
fairy(r);
}
if(m==t)
{ extern time_t ts,te,d;
te=time(NULL);
d=te-ts;
printf(" your are right,congratuations to you!");
jishi(d);
}
}
void jishi(time_t a)
{ if(a>=0&&a<10)
printf("\nperfect! your time is %ld seconds",a);
if(a>=10&&a<60)
printf("\nso so.your time is %ld seconds",a);
if(a>=60)
printf("\noh shit! your time is %ld seconds",a);
}
第3个回答  2007-09-07
你这里有什么问题?说说问题吧,我现在电脑上没装C

c语言编程题,请高手帮忙做一下,拜谢,急急急急……
1.include <stdio.h> double funcPi(int);int main(void){ int arg;printf("Input the argument: ");\/\/ \/\/ 无异常输入 \/\/ while (!scanf("%d", &arg)){ printf("Check your input and retry: ");while (getchar()!='\\n'){ continue;} } while (getchar()!='\\n'){ continue...

c语言问题,高手请进谢谢!!!
1、++i 时i加1得到i,此时的i=2;2、++i 时i加1得到i,此时的i=2+1=3;3、此时前面有两个i等待运行,即i+i--->这两个i些时都是3;而不是一个2,一个3;4。再一个++i 此时i加1得到i,i=3+1=4;由上面的理解知道i此时已经是4,5、由上面四步得到一个i=4,i+i+i的式...

C语言编写闰年高手看下提点下
if(year%4==0){ if(year%100==0){ if(year%100==0){ if(year%400==0)leap=1;else leap=0;} else leap=1;} else leap=0;改为 if(year%4==0 && year%100!=0) leap=1;else if(year%400==0) leap=1;else leap=0;能被4整除,但不能被100整除的是闰年;能被100整除,又...

C语言的高手进来看看!!
可以这么来,先设一个全局变两,然后在你想引用的变量所在的函数中将该变量的值赋给你之前设的全局变量,这样你就可以通过引用这个全局变量来实现你要的引用了。

c语言高手请帮忙看看
C语言规定,函数用之前要先定义的,你的函数ads在用之前没定义,你将ads函数放在main()前面就对了 include<conio.h> include<string.h> include<stdio.h> ads(int x,int y,int z){ printf("(2)x=%d,y=%d,z=%d\\n",x,y,z);x=y+z;y=y*y;z=z*z;printf("(3)x=%d,y=%d,z=...

C语言的问题 请高手帮忙回答 谢谢~!~急···
肯定有15 while (i<15)if(++i%3!=0) continue;else printf(“%3d”,i);} 当i=14时,进入循环,先执行++i进行if判断,此时i变成15,if条件不满足(15%3==0),执行else,打印15

C语言大神帮我看一下谢谢。In function 'void professionall...
void professionall(){ char UserChoose, professional[10], Turn;printf("现在请先选择职业:\\n");printf("1.窃贼(敏捷10,力量3,智力,6)\\n2.战士(敏捷3,力量8,智力3)\\n3.骑士(敏捷6,力量6,智力7)\\n请输入相对应序号(各属性之后可以增强): ");UserChoose = getchar();while...

一道C语言编程问题,高手们来看看帮忙解答下
for (c = b-1;c > 0;c--)\/\/以C为循环变量,在1到B之间。{ \/\/判断公式左右两侧是不是相等,相等侧符合题目要求 if (c*c*(a*a+b*b) == a*a*b*b){ sum = a+b+c; \/\/判定成立,求和 printf("SUM = %d\\nA = %d\\nB = %d\\nC = %d\\n",sum,a,b,c);return 0;} ...

c语言,本人菜鸟,高手来
先看下运算符的优先级 ()\/ 除 表达式\/表达式 左到右 双目运算符 乘 表达式*表达式 双目运算符 左到右 余数(取模) 整型表达式\/整型表达式 双目运算符 左到右 + 加 表达式+表达式 左到右 先算(),x+a%3*(int)(x+y)%2\/4 = x+a%3*7%2\/...

C语言高手帮忙啊!急!!!
;while(p!=NULL){ printf("%d,",p->data);p=p->next;} } void main(){ linklist *L;L=CREAT();LENGTH(L);OUT(L);} 该程序在turboc2.0上运行成功。顺便说一下:其实我这学期刚学《数据结构》,我想你也应该在学这门课吧,不知道可否交个朋友,以后好互相讨教。QQ:729430705 ...

相似回答
大家正在搜