请达人帮我看下这个C程序,有一处错误,改不出来

来源:百度知道 编辑:UC知道 时间:2024/06/30 17:06:14
#include<STDIO.H>
#include<stdlib.h>
#include<time.h>
main()
{
int n,i,t,a,b;
int sgn,key,score=0;
printf("Please input the number is:\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
a=fand()%10;
b=fand()%10;
sgn=fand%4;
if(sgn==0)
{printf("%d+%d=",a,b);
scanf("%d",&key);
if(key==a+b)
{score++;
printf("right\n");
}
else
printf("wrong\n");
}
if(sgn==1)
{
if(a<b)
{
t=a;a=b;b=t;
}
printf("%d-%d=",a,b);
scanf("%d",&key);
if(key==a-b)
{
score++;
printf("right\n");
}
else
printf("wrong\n");
}
if(sgn==2)
{
printf("%d*%d=",a,b);
scanf("%

a=fand()%10;
b=fand()%10;
sgn=fand%4;

改为如下形式:

a=rand()%10;
b=rand()%10;
sgn=rand()%4;

另外,在scanf("%d",&n); 之后加上以下语句:

srand(time(NULL));

在WXD修改的基础上,再加上一个修改:
printf("Your score is:%.2f\n",score/n*100);
改成:
printf("Your score is:%.2f\n",(float)score/n*100);

你的第14行出错。fands:undeclared identifier。就是说你14行中的fands未定义。