万年历法的程序,有点问题~请各位指教
#include<iostream>using namespace std;
#include<iomanip>
int firstday(int year) //计算当年第一天是星期几
{
int s, k;
s=year-1990;
k=1+(s-1)/4+1;
return (int)k;
}
void print(int s,int firstday) //输出12个月
{
cout<<" 日 "<<"一 "<<"二 "<<"三 "<<"四 "<<"五 "<<"六 "<<endl;
for(int j=firstday;j>0;j--)
cout<<" ";
for(int i=1;i<=s;i++)
{
cout<<" "<<setw(2)<<i;
firstday=(firstday+1)%7;
if(firstday==0)
cout<<endl;
}
cout<<endl;
}
int monthday(int n,int year) //计算一个月有多少天
{
if((n==1)||(n==3)||(n==5)||(n==7)||(n==8)||(n==10)||(n==12))
return 31;
if(n==2)
{
if((year%4==0&&year%100!=0)||(year%400==0))
return 29;
else
return 28;
}
else
return 30;
}
void main()
{
int i,year,f,m;
cout<<"year:";
cin>>year;
cout<<endl;
f=firstday(year);
for(i=1;i<=12;i++) //控制输出12个月
{
cout<<" "<<i<<"月"<<endl;
m=monthday(i,year);
print(m,f);
}
}
估计是红色的地方出了问题??