大家帮我修改一下这个程序的错误咯在线等,立结!
#include<stdio.h> #include<stdlib.h> /*定义头文件*/
int runnian(int year)/*定义变量*/
{
if(year%4==0&&year%100!=0||year%400==0) /*利用函数判断输入年份是闰年还是平年*/
return 1;
else
return 0;
}
int day1(int year,int month)
{
int a[12]={31,28,31,30,31,30,31,31,30,31,30,31};/*定义数组确定12个月每个月的天数*/
if(runnian(year)) /*如果输入年份是闰年*/
a[1]=29;/*二月29天*/
return a[month-1];
}
int day2(int year,int month,int day),
int i,sum=0;
for(i=1;i<month;i++)
{
sum+=day1(year,i);
}
sum+=day;
return sum;
}
int week1(int year,int month,int day)
{
int number=(year-1)+(year-1)/4-(year-1)/100+(year-1)/400+day2(year,month,day);
number%=7;
return number;
}
char *Week2(int number)
{
switch(number)/*分类一周七天*/
{
case 0:
return "星期日";
case 1:
return "星期一";
case 2:
return "星期二";
case 3:
return "星期三";
case 4:
return "星期四";
case 5:
return "星期五";
case 6:
return "星期六";
default:
return "错误!请您重新输入。";/*不符和上面七种情况的报错提示*/
}
}
void x1(int year,int month,int day)
{
int number=week1(year,month,day);
if(runnian(year))printf("闰年");/*年份为闰年则输出"闰年"*/
else printf("平年");
printf(" %d 年 %d 月 %d 日%10s\n\n",year,month,day,Week2(number));/*按年 月 日输出结果*/
}
void x2(int year,int month)
{
int max,number,i,j=1;
max=day1(year,month);
number=week1(year,month,1);
printf("%2s%2s%2s%2s%2s%2s%2s\n"," 星期日 "," 星期一 "," 星期二"," 星期三 "," 星期四 "," 星期五 "," 星期六 ");/*按照间隔打印日历
for(i=0;i<number;i++)
{
printf(" ");
}
while(j<=max)
{
printf("%8d",j);
if(i%7==6)
{
printf("\n");
}
i++;
j++;
}
printf("\n\n");
}
int x3(int year,int month,int day)
{
if(year<0||month<1||month>12||day<1||day>day1(year,month))/*当输入植出现这些情况时*/
return 0;/*返回0*/
else
return 1;/*返回1*/
}
void nianli(int year)
{
int i;
printf("\n");
for(i=1;i<=12;i++)
{
if(runnian(year))printf("闰年");
else printf("平年");
printf(" %d 年 %d 月\n\n",year,i);
}
}
void yueli(int year,int month)
{
if(runnian(year))
printf("闰年");
else printf("平年");
printf(" %d 年 %d 月\n\n",year,month);
x2(year,month);
}
void rili(int year,int month,int day)
{
printf("\n");
x1(year,month,day);
}
void main()
{
int year,month,day,a,b;
while(1)
{
printf("\n\n\n\n");
printf(" **********************************************************\n\n");
printf(" * * \n");
printf(" 欢迎进入万年历查询系统 \n");
printf(" * * \n\n");
printf(" **********************************************************\n\n\n");
printf(" 1 年历 2 月历 3 日历 4 退出\n");
printf(" 请输入您的选择<1~4>,按回车键确定: ");
scanf("%d",&b);
switch(b)
{
case 1:/*选择1时*/
printf("\n请输入您要查的年份: ");/*给出输入提示*/
scanf("%d",&year);/*输入查询的年份*/
a=x3(year,1,1);
if(a==0)
{
printf("错误!请您重新输入。\n");/*输入植异常时报错*/
break;
}
nianli(year);
break;
case 2:/*选择二时*/
printf("\n请输入您要查的年和月,年月之间用空格隔开: ");/*给出输入提示*/
scanf("%d%d",&year,&month);/*输入需要查询的年 月*/
a=x3(year,month,1);
if(a==0)
{
printf("错误!请您重新输入。\n");
break;
}
yueli(year,month);
break;
case 3:/*选择3时*/
printf("\n请输入您要查的年月日,年月日之间用空格隔开: ");/*给出输入提示*/
scanf("%d%d%d",&year,&month,&day);/*输入年 月 日*/
a=x3(year,month,day);
if(a==0)
{
printf("错误!请您重新输入。\n");/*输入植异常时报错*/
break;
}
rili(year,month,day);
break;
case 4:
exit(0);
default:
printf("错误!请您重新输入。\n\n");
}
}
}
--------------------Configuration: cnc - Win32 Debug--------------------
Compiling...
cnc.c
C:\Documents and Settings\joaquin\My Documents\c\cnc.c(18) : error C2059: syntax error : 'type'
C:\Documents and Settings\joaquin\My Documents\c\cnc.c(19) : error C2059: syntax error : 'for'
C:\Documents and Settings\joaquin\My Documents\c\cnc.c(19) : error C2143: syntax error : missing '{' before '<'
C:\Documents and Settings\joaquin\My Documents\c\cnc.c(19) : error C2059: syntax error : '<'
C:\Documents and Settings\joaquin\My Documents\c\cnc.c(19) : error C2143: syntax error : missing '{' before '++'
C:\Documents and Settings\joaquin\My Documents\c\cnc.c(19) : error C2059: syntax error : '++'
C:\Documents and Settings\joaquin\My Documents\c\cnc.c(19) : error C2059: syntax error : ')'
C:\Documents and Settings\joaquin\My Documents\c\cnc.c(23) : error C2143: syntax error : missing '{' before '+='
C:\Documents and Settings\joaquin\My Documents\c\cnc.c(23) : error C2059: syntax error : '+='
C:\Documents and Settings\joaquin\My Documents\c\cnc.c(24) : error C2059: syntax error : 'return'
C:\Documents and Settings\joaquin\My Documents\c\cnc.c(25) : error C2059: syntax error : '}'
C:\Documents and Settings\joaquin\My Documents\c\cnc.c(56) : warning C4013: 'week1' undefined; assuming extern returning int
C:\Documents and Settings\joaquin\My Documents\c\cnc.c(87) : error C2181: illegal else without matching if
C:\Documents and Settings\joaquin\My Documents\c\cnc.c(88) : warning C4098: 'x2' : 'void' function returning a value
C:\Documents and Settings\joaquin\My Documents\c\cnc.c(133) : warning C4013: 'x3' undefined; assuming extern returning int
执行 cl.exe 时出错.
cnc.obj - 1 error(s), 0 warning(s)
[ 本帖最后由 monima15 于 2013-2-28 21:15 编辑 ]