单片机运行下列程序出现以下错误,望高手解答,不胜感激 10
#include<stdio.h>#defineunitvoidmain(){intadd();intminus();intmul();intm,n=0,a=0,b=0,...
#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
程序有没有错误,望指导 展开
#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
程序有没有错误,望指导 展开
展开全部
用WINTC 可以编译
stdio.h的头文件里没有srand()函数和timer()函数
估计把WINTC根目录里的stdio.h文件被keil51里的stdio.h文件也没法编译,因为编译器不一样
keil51里的stdio.h文件里内容如下:
/*--------------------------------------------------------------------------
STDIO.H
Prototypes for standard I/O functions.
Copyright (c) 1988-2002 Keil Elektronik GmbH and Keil Software, Inc.
All rights reserved.
--------------------------------------------------------------------------*/
#ifndef __STDIO_H__
#define __STDIO_H__
#ifndef EOF
#define EOF -1
#endif
#ifndef NULL
#define NULL ((void *) 0)
#endif
#ifndef _SIZE_T
#define _SIZE_T
typedef unsigned int size_t;
#endif
#pragma SAVE
#pragma REGPARMS
extern char _getkey (void);
extern char getchar (void);
extern char ungetchar (char);
extern char putchar (char);
extern int printf (const char *, ...);
extern int sprintf (char *, const char *, ...);
extern int vprintf (const char *, char *);
extern int vsprintf (char *, const char *, char *);
extern char *gets (char *, int n);
extern int scanf (const char *, ...);
extern int sscanf (char *, const char *, ...);
extern int puts (const char *);
#pragma RESTORE
#endif
stdio.h的头文件里没有srand()函数和timer()函数
估计把WINTC根目录里的stdio.h文件被keil51里的stdio.h文件也没法编译,因为编译器不一样
keil51里的stdio.h文件里内容如下:
/*--------------------------------------------------------------------------
STDIO.H
Prototypes for standard I/O functions.
Copyright (c) 1988-2002 Keil Elektronik GmbH and Keil Software, Inc.
All rights reserved.
--------------------------------------------------------------------------*/
#ifndef __STDIO_H__
#define __STDIO_H__
#ifndef EOF
#define EOF -1
#endif
#ifndef NULL
#define NULL ((void *) 0)
#endif
#ifndef _SIZE_T
#define _SIZE_T
typedef unsigned int size_t;
#endif
#pragma SAVE
#pragma REGPARMS
extern char _getkey (void);
extern char getchar (void);
extern char ungetchar (char);
extern char putchar (char);
extern int printf (const char *, ...);
extern int sprintf (char *, const char *, ...);
extern int vprintf (const char *, char *);
extern int vsprintf (char *, const char *, char *);
extern char *gets (char *, int n);
extern int scanf (const char *, ...);
extern int sscanf (char *, const char *, ...);
extern int puts (const char *);
#pragma RESTORE
#endif
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
/* time.h
Struct and function declarations for dealing with time.
Copyright (c) Borland International 1987,1988
All Rights Reserved.
*/
#if __STDC__
#define _Cdecl
#else
#define _Cdecl cdecl
#endif
#ifndef _TM_DEFINED
#define _TM_DEFINED
#ifndef __TIME_T
#define __TIME_T
typedef long time_t;
#endif
#ifndef __CLOCK_T
#define __CLOCK_T
typedef long clock_t;
#define CLK_TCK 18.2
#endif
struct tm {
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday;
int tm_yday;
int tm_isdst;
};
char *_Cdecl asctime (const struct tm *tblock);
char *_Cdecl ctime (const time_t *time);
double _Cdecl difftime(time_t time2, time_t time1);
struct tm *_Cdecl gmtime(const time_t *timer);
struct tm *_Cdecl localtime(const time_t *timer);
time_t _Cdecl time (time_t *timer);
clock_t _Cdecl clock(void);
#if !__STDC__
extern int _Cdecl daylight;
extern long _Cdecl timezone;
int _Cdecl stime(time_t *tp);
void _Cdecl tzset(void);
#endif
#endif
把这个另存为time.h文件,然后在你的程序头引用。
Struct and function declarations for dealing with time.
Copyright (c) Borland International 1987,1988
All Rights Reserved.
*/
#if __STDC__
#define _Cdecl
#else
#define _Cdecl cdecl
#endif
#ifndef _TM_DEFINED
#define _TM_DEFINED
#ifndef __TIME_T
#define __TIME_T
typedef long time_t;
#endif
#ifndef __CLOCK_T
#define __CLOCK_T
typedef long clock_t;
#define CLK_TCK 18.2
#endif
struct tm {
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday;
int tm_yday;
int tm_isdst;
};
char *_Cdecl asctime (const struct tm *tblock);
char *_Cdecl ctime (const time_t *time);
double _Cdecl difftime(time_t time2, time_t time1);
struct tm *_Cdecl gmtime(const time_t *timer);
struct tm *_Cdecl localtime(const time_t *timer);
time_t _Cdecl time (time_t *timer);
clock_t _Cdecl clock(void);
#if !__STDC__
extern int _Cdecl daylight;
extern long _Cdecl timezone;
int _Cdecl stime(time_t *tp);
void _Cdecl tzset(void);
#endif
#endif
把这个另存为time.h文件,然后在你的程序头引用。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
C51编译器不提供有关系统时间函数的定义,有别于TC等编译器,TC\INC\下有time.h,而C51编译器没有。
追问
那是说不能用有关系统时间函数还是说可以有其他使用方法,请指点
追答
C51编译器与传统C编译器有较大差别,是不能用有关系统时间函数等好多函数。
只有基本的i\o函数,math函数等少数几个。
你的C下的程序是不能直接移植到C51编译器下的。
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询