为什么只有2024年的输出是正确的?
#include <iostream>#include <iomanip>
using namespace std;
int main(){
int n=0;
int y=0;
int day=0;
int days=0;
int a[]={31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
cout<<"请输入年份和月份:"<<endl;
cin>>n>>y;
if(n<2024){
cout<<"请输入更大的年份:"<<endl;
return 0;
}
if(y<1||y>12){
cout<<"错误,请重新输入:";
return 0;
}
switch (y) {
case 12:
day+=30;
case 11:
day+=31;
case 10:
day+=30;
case 9:
day+=31;
case 8:
day+=31;
case 7:
day+=30;
case 6:
day+=31;
case 5:
day+=30;
case 4:
day+=31;
case 3:
day+=(n % 4 == 0 && n% 100 != 0 || n % 400 == 0) ? 29 : 28;
case 2:
day+=31;
}
for(int i=2024;i<n;i++){
if(n % 4 == 0 && n% 100 != 0 || n % 400 == 0){
days+=366;
}
else {
days+=365;
}
}
int sum=day+days;
int j=sum%7+1;
cout <<"---------------------"<< endl;
cout <<" Su Mo Tu We Th Fr Sa"<< endl;
cout <<"---------------------"<< endl;
for(int k=0;k<j;k++){
cout<<" ";
}
if ((n % 4 == 0 && n% 100 != 0 || n % 400 == 0)&& y == 2){
a[y-1] += 1;
}
int w=7-j;
for(int i=1;i<=a[y-1];i++){
cout<<setw(3)<<i;
if((i-w)%7==0){
cout<<endl;
}
}
return 0;
}