c程序c++问题:下面的程序不知道为什么错误,编译,连接都没问题,但是就是运行到最后显示分数时发生错误
#include<stdio.h>intshow(){inta,b,t,op,answer0;srand(time());a=rand()%10+1;b=rand()%1...
#include<stdio.h>
int show()
{
int a,b,t,op,answer0;
srand(time());
a=rand()%10+1;
b=rand()%10+1;
op=rand()%2+0;
switch(op)
{
case 0:printf("%d+%d=",a,b);
answer0=a+b;
break;
case 1:
if(a<b){t=a;a=b;b=t;}
printf("%d-%d=",a,b);
answer0=a-b;
break;
}
return(answer0);
}
int Test(int t_answer1,int t_answer0)
{
if(t_answer1==t_answer0)
{
printf("Right!\n");
return 1;
}
else
{
printf("Not correct !\n");
return 0;
}
}
main()
{
int i,an_flag;
int answer1,answer2,score=0;
for(i=0;i<10;i++)
{
answer1=show();
scanf("%d",&answer2);
an_flag=Test(answer1,answer2);
if(an_flag==1)
score+=10;
}
printf("\nRight score:%d\n",score);
}
请高手指点一下,谢谢。 展开
int show()
{
int a,b,t,op,answer0;
srand(time());
a=rand()%10+1;
b=rand()%10+1;
op=rand()%2+0;
switch(op)
{
case 0:printf("%d+%d=",a,b);
answer0=a+b;
break;
case 1:
if(a<b){t=a;a=b;b=t;}
printf("%d-%d=",a,b);
answer0=a-b;
break;
}
return(answer0);
}
int Test(int t_answer1,int t_answer0)
{
if(t_answer1==t_answer0)
{
printf("Right!\n");
return 1;
}
else
{
printf("Not correct !\n");
return 0;
}
}
main()
{
int i,an_flag;
int answer1,answer2,score=0;
for(i=0;i<10;i++)
{
answer1=show();
scanf("%d",&answer2);
an_flag=Test(answer1,answer2);
if(an_flag==1)
score+=10;
}
printf("\nRight score:%d\n",score);
}
请高手指点一下,谢谢。 展开
1个回答
展开全部
帮你修改了下,就是一些小问题。希望对你有帮助
#include<stdio.h>
#include <stdlib.h>
#include <time.h>
int show()
{
int a,b,t,op,answer0;
srand(time(NULL));
a=rand()%10+1;
b=rand()%10+1;
op=rand()%2+0;
switch(op)
{
case 0:printf("%d+%d=",a,b);
answer0=a+b;
break;
case 1:
if(a<b){t=a;a=b;b=t;}
printf("%d-%d=",a,b);
answer0=a-b;
break;
}
return(answer0);
}
int Test(int t_answer1,int t_answer0)
{
if(t_answer1==t_answer0)
{
printf("Right!\n");
return 1;
}
else
{
printf("Not correct !\n");
return 0;
}
}
void main()
{
int i,an_flag;
int answer1,answer2,score=0;
for(i=0;i<10;i++)
{
answer1=show();
scanf("%d",&answer2);
an_flag=Test(answer1,answer2);
if(an_flag==1)
score+=10;
}
printf("\nRight score:%d\n",score);
}
#include<stdio.h>
#include <stdlib.h>
#include <time.h>
int show()
{
int a,b,t,op,answer0;
srand(time(NULL));
a=rand()%10+1;
b=rand()%10+1;
op=rand()%2+0;
switch(op)
{
case 0:printf("%d+%d=",a,b);
answer0=a+b;
break;
case 1:
if(a<b){t=a;a=b;b=t;}
printf("%d-%d=",a,b);
answer0=a-b;
break;
}
return(answer0);
}
int Test(int t_answer1,int t_answer0)
{
if(t_answer1==t_answer0)
{
printf("Right!\n");
return 1;
}
else
{
printf("Not correct !\n");
return 0;
}
}
void main()
{
int i,an_flag;
int answer1,answer2,score=0;
for(i=0;i<10;i++)
{
answer1=show();
scanf("%d",&answer2);
an_flag=Test(answer1,answer2);
if(an_flag==1)
score+=10;
}
printf("\nRight score:%d\n",score);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询