【求各位大神帮助!!】EXE停止工作
#include <time.h> #include<stdlib.h>
#include <stdio.h>
#include <dos.h>
#include <conio.h>
#include<stdlib.h>
int random(int x);
int question(void);
void output(int x,char p[][30]);
int random(int x) //产生随机数的函数
{
int r;
srand((unsigned)time(NULL));
r=rand()%x;
return(r);
}
int question()//生成题目的函数
{
int a,b,c,z;
srand((unsigned)time(NULL));
LOOP:a=rand()%50;//a在0到50内取值
b=rand()%50;//b在0到50内取值
c=random(2);
if(c==0)//0到1内取整数,若等于0生成加法,等于1生成减法
{
z=a+b;
if(z<0||z>50)//判断z是否在0到50之间
goto LOOP;
printf("%d+%d=\n",a,b);
}
else
{
z=a-b;
if(z<0||z>50)//判断z是否在0到50之间
goto LOOP;
printf("%d-%d=\n",a,b);
}
return(z);
}
void output(int x,char p[][30])//生成评价的程序
{
int i,j;
j=random(x);
i=0;
do
{
printf("%s",p[j][i]);
i++;
}
while(p[j][i]=='\0');
printf("\n");
}
int main()
{
int i,k,score=0,result;
char a[][30]={{"Right!"},{"Correct!"},{"You got it!"},{"The answer is right!"},{"Gaoging!"}};
char b[][30]={{"Error! Try again, please."},{"Wrong! Once more, please."},{"No! A second time, please"}};
char c[][30]={{"Error! Try again, please."},{"Wrong! Once more, please."},{"No! The last time, please"}};
time_t first,second;
srand((int)time(0));
first=time(NULL); //计时开始
for(i=0;i<10;i++)
{
result=question();//生成题目
printf("请输入答案:\n");
scanf("%d",&k);
if(k=result)
{
score=score+10;
output(5,a);
}
else
{
output(3,b);
printf("请输入答案:\n");
scanf("%d",&k);
if(k=result)
{
score=score+7;
output(5,a);
}
else
{
output(3,c);
printf("请输入答案:\n");
scanf("%d",&k);
if(k=result)
{
score=score+5;
output(5,a);
}
else
{
printf("No, the answer is %d",result);
}
}
}
}
second=time(NULL); //计时结束
printf("共用时:%f seconds\n",difftime(second,first));
printf("总分为:%d\n",score);
getch();
return 0;
}
刚学习C语言,好多还不熟练,捣鼓了一晚上才把错误全部解决,可是一运行每当输入完敲空格就跳出EXE停止工作,求各位大神帮助啊!~~