#include<stdio.h>
#define unit
void main()
{
int add();
int minus();
int mul();
int m,n=0,a=0,b=0,c=0,d;
do
{ printf("what category do you want to test?\n");
printf("1,add,2,minus,3,multiplication\n");
scanf("%d",&d);
switch(d)
{ case 1: a=add();break;
case 2: b=minus();break;
case 3: c=mul();break;
default:unit;
}
printf("do you want to continue other test?\n");
printf("1,yes,2,no\n");
scanf("%d",&m);
n=n+a+b+c;
}
while(m==1);
printf("the total score is:%d\n",n);
}
add()
{
int a,b,c,d,sum=0,total1=0;
srand((unsigned)time(NULL));
do
{ a=rand()%90+10;
b=rand()%90+10;
printf("%d+%d=",a,b);
scanf("%d",&c);
sum=a+b;
if(c==sum)
{ printf("you are right\n");
total1++;
}
else
printf("sorry,the answer is%d\n",sum);
printf("do you want to continue?\n");
printf("1,yes,2,no\n");
do
{ scanf("%d",&d);
if(d!=1&&d!=2)
printf("the select is wrong\n");
}
while(d!=1&&d!=2);
}
while(d==1);
return(total1);
}
minus()
{ int a,b,c,d,t,dif=0,total2=0;
srand((unsigned)time(NULL));
do
{ a=rand()%90+10;
b=rand()%90+10;
if(a<b)
{ t=a;
a=b;
b=t;
}
printf("%d-%d=",a,b);
scanf("%d",&c);
dif=a-b;
if(c==dif)
{ printf("you are right\n");
total2++;
}
else
printf("sorry,the answer is%d\n",dif);
printf("do you want to continue?\n");
printf("1,yes,2,no\n");
do
{ scanf("%d",&d);
if(d!=1&&d!=2)
printf("the select is wrong\n");
}
while(d!=1&&d!=2);
}
while(d==1);
return(total2);
}
mul()
{ int a,b,c,d,mul=0,total3=0;
srand((unsigned)time(NULL));
do
{ a=rand()%10;
b=rand()%10;
printf("%d*%d=",a,b);
scanf("%d",&c);
mul=a*b;
if(c==mul)
{ printf("you are right\n");
total3++;
}
else
printf("sorry,the answer is%d\n",mul);
printf("do you want to continue?\n");
printf("1,yes,2,no\n");
do
{ scanf("%d",&d);
if(d!=1&&d!=2)
printf("the select is wrong\n");
}
while(d!=1&&d!=2);
}
while(d==1);
return(total3);
}
错误显示如下:TURBOC2\CYUYANCH.C(31): warning C206: 'time': missing function-prototype
TURBOC2\CYUYANCH.C(31): error C267: 'time': requires ANSI-style prototype
程序有没有错误,望指导
那是说不能用有关系统时间函数还是说可以有其他使用方法,请指点
追答C51编译器与传统C编译器有较大差别,是不能用有关系统时间函数等好多函数。
只有基本的i\o函数,math函数等少数几个。
你的C下的程序是不能直接移植到C51编译器下的。