为什么这个万年历的程序不能显示某年某月有的天数
这个程序为什么显示不了某年某月有的天数,,选择2不显示,请大家帮忙。。。#include<iostream.h>
#include<stdlib.h>
#include<stdio.h>
#include<iomanip.h>
struct mon
{
int maxdata;
int data;
};
int SeekWeekDay(void);
int WeekDay(int year,int month,int day);
int HowManyDays(void);
int MonthDays(int year,int month);
int PrintWeek(int weekday);
int PrintMonth(int month);
int PrintData(void);
int main()
{
char choice;
while(1)
{
puts("*******************************");
puts("*请输入您的选择: *");
puts("*输入1求某个日期对应的星期 *");
puts("*输入2求某年某月有的天数 *");
puts("*输入3输出某年的日历 *");
puts("*输入Q结束程序 *");
puts("*******************************");
cin>>choice;
fflush(stdin);
switch(choice)
{
case '1':SeekWeekDay(); break;
case '2':int HowManyDays(int) ; break;
case '3':PrintData(); break;
case 'Q':return 0;
default: puts("输入错误,请重新输入");break;
}
cout<<endl<<endl;
}
system("pause");
return 0;
}
int HowWanyDays(int)
{
int year,month,days;
cout<<"请输入年号和月份:";
cin>>year>>month;fflush(stdin);
cout<<"你的输入为"<<year<<"年"<<month<<"月,";
days=MonthDays(year,month);
cout<<year<<"年"<<month<<"月有"<<days<<"天\n";
return 0;
}
SeekWeekDay()
{
int year,month,day,weekday;
cout<<"请输入年 月 日:";
cin>>year>>month>>day; fflush(stdin);
cout<<"你的输入为"<<year<<"年"<<month<<"月"<<day<<"日\n";
weekday=WeekDay(year,month,day);
cout<<"这天是" ;
//int PrintWeek(int weekday);
PrintWeek(weekday);
return 0;
}
PrintWeek(int weekday)
{
switch(weekday)
{
case 0:cout<<"周日";break;
case 1:cout<<"周一";break;
case 2:cout<<"周二";break;
case 3:cout<<"周三";break;
case 4:cout<<"周四";break;
case 5:cout<<"周五";break;
case 6:cout<<"周六";break;
}
return 0;
}
PrintMonth(int month)
{
switch(month)
{
case 1:cout<<"一 月"; break;
case 2:cout<<"二 月"; break;
case 3:cout<<"三 月"; break;
case 4:cout<<"四 月"; break;
case 5:cout<<"五 月"; break;
case 6:cout<<"六 月"; break;
case 7:cout<<"七 月"; break;
case 8:cout<<"八 月"; break;
case 9:cout<<"九 月"; break;
case 10:cout<<"十 月";break;
case 11:cout<<"十一 月";break;
case 12:cout<<"十二 月";break;
}
return 0;
}
int WeekDay(int year,int month,int day)
{
int i;
int run=0,ping=0;
long sum;
for(i=1;i<year;i++)
{
if(i%4==0 && i%100!=0||i%400==0)
run++;
else
ping++;
}
sum=366*run+365*ping;
for(i=1;i<month;i++)
sum+=MonthDays(year,i);
sum+=day;
return(int)sum&7;
}
int MonthDays(int year,int month)
{
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12: return 31;
case 4:
case 6:
case 9:
case 11: return 30;
case 2:
if(year%4==0 && year&100!=0|| year%400==0)
return 29;
else
return 28;
default:cout<<"这是一个错误的月份!";system("pause");
return 0;
}
}
int PrintData(void)
{
struct mon month[13];
int i,j,k;
int year,mon,week;
cout<<"请输入年号" ;
cin>>year;
for(i=1;i<13;i++)
{
month[i].data=1;
month[i].maxdata=MonthDays(year,i);
}
for(i=0;i<6;i++)
{
for(j=1;j<=2;j++)
{
mon=2*i+j;
cout<<setw(20);
PrintMonth(mon);
cout<<setw(20);
if(j==1)
cout<<'\t';
}
cout<<endl;cout<<endl;
for(j=1;j<=2;j++)
{
for(k=0;k<7;k++)
{
PrintWeek(k);
}
cout<<setw(3)<<' ';
}
cout<<endl;
for(j=1;j<=2;j++)
{
mon=2*i+j;
week=WeekDay(year,mon,1);
if( j==1)
cout<<setw(week*5+5)<<month[mon].data++;
else
cout<<setw(week*4.8)<<month[mon].data++;
week++;
while(week<7)
{
cout<<setw(5)<<month[mon].data++;
week++;
}
if(j==1)
cout<<setw(11)<<' ';
}
cout<<endl;cout<<endl;
while(month[2*i+1].data<=month[2*i+1].maxdata||month[2*i+2].data<=month[2*i+2].maxdata)
{
for(j=1;j<=2;j++)
{
mon=2*i+j;
for(k=0;k<7;k++)
{
if(month[mon].data<=month[mon].maxdata)
cout<<setw(5)<<month[mon].data++;
else
cout<<" ";
}
if(j==1)
cout<<'\t';
}
cout<<endl;cout<<endl;
}
cout<<endl;
}
return 0;
}