主题:大家帮帮帮忙拉,关于函数声明,调用,定义
#include <stdio.h>
#include <stdlib.h>
struct DATE {int year,month,day;};
int IsLeapYear (int year);
void PrintWelcomInfol ();
struct DATE GeteDate (struct DATE date);
int ToDealWith (struct DATE date);
void PrintRssult (int date_id);
int main()
{ int date_id;
struct DATE date;
PrintWelcomInfol ();
GeteDate ( date);
date_id=ToDealWith ( date);
PrintRssult (date_id);
system("PAUSE");
return 0;
}
int IsLeapYear (int year)
{
if(year%4==0&&year%100!=0||year%400==0)return 1;
else return 0;
}
void PrintWelcomInfol ()
{
printf("The program");
}
struct DATE GeteDate(struct DATE date)
{
printf("Please input the year:\n");scanf("%d",&date.year);
printf("Please input the month:\n");scanf("%d",&date.month);
printf("Please input the day:\n");scanf("%d",&date.day);
if(date.year<1990||date.month>12)printf(" ERROR,please input right date\n");
switch(date.month){
case 1: case 3: case 5: case 7: case 8: case 10: case 12: if(date.day>31)
{printf("ERROR,please input right date\n"); break;}
case 4: case 6: case 9: case 11: if(date.day>30)
{printf("ERROR,please input right date\n");break;}
case 2: if(date.day>(28+(IsLeapYear (date.year))))
{printf("ERROR,please input right date\n");;break;}
default:;
return date;
}
int ToDealWith (struct DATE date)
{
unsigned int day_of_month[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
unsigned int i,date_id=0;
for(i=0;i<date.year;++i)
{
date_id+=365;
date_id+=IsLeapYear(date.year);
}
for(i=0;i<date.month;++i)
date_id+=day_of_month[i];
date_id+=date.day;
if(a.month>2&&IsLeapYear (a.year))
date_id++;
return date_id;
}
void PrintRssult (int date_id)
{
if(date_id%5>0&&date_id%5<=3)printf("%d年%d月%d日他在..",a.year,a.month,a.day);
else printf("%d年%d月%d日他在",a.year,a.month,a.day);
}
编译时总会出现下面一行东东
46 C:\Documents and Settings\user\桌面\Untitled1.cpp a function-definition is not allowed here before '{' token
大家帮忙拉,谢谢
#include <stdlib.h>
struct DATE {int year,month,day;};
int IsLeapYear (int year);
void PrintWelcomInfol ();
struct DATE GeteDate (struct DATE date);
int ToDealWith (struct DATE date);
void PrintRssult (int date_id);
int main()
{ int date_id;
struct DATE date;
PrintWelcomInfol ();
GeteDate ( date);
date_id=ToDealWith ( date);
PrintRssult (date_id);
system("PAUSE");
return 0;
}
int IsLeapYear (int year)
{
if(year%4==0&&year%100!=0||year%400==0)return 1;
else return 0;
}
void PrintWelcomInfol ()
{
printf("The program");
}
struct DATE GeteDate(struct DATE date)
{
printf("Please input the year:\n");scanf("%d",&date.year);
printf("Please input the month:\n");scanf("%d",&date.month);
printf("Please input the day:\n");scanf("%d",&date.day);
if(date.year<1990||date.month>12)printf(" ERROR,please input right date\n");
switch(date.month){
case 1: case 3: case 5: case 7: case 8: case 10: case 12: if(date.day>31)
{printf("ERROR,please input right date\n"); break;}
case 4: case 6: case 9: case 11: if(date.day>30)
{printf("ERROR,please input right date\n");break;}
case 2: if(date.day>(28+(IsLeapYear (date.year))))
{printf("ERROR,please input right date\n");;break;}
default:;
return date;
}
int ToDealWith (struct DATE date)
{
unsigned int day_of_month[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
unsigned int i,date_id=0;
for(i=0;i<date.year;++i)
{
date_id+=365;
date_id+=IsLeapYear(date.year);
}
for(i=0;i<date.month;++i)
date_id+=day_of_month[i];
date_id+=date.day;
if(a.month>2&&IsLeapYear (a.year))
date_id++;
return date_id;
}
void PrintRssult (int date_id)
{
if(date_id%5>0&&date_id%5<=3)printf("%d年%d月%d日他在..",a.year,a.month,a.day);
else printf("%d年%d月%d日他在",a.year,a.month,a.day);
}
编译时总会出现下面一行东东
46 C:\Documents and Settings\user\桌面\Untitled1.cpp a function-definition is not allowed here before '{' token
大家帮忙拉,谢谢