int main()
{
int year,month,day;
int i,j=28,days=0;
cout<<"Input date(yyyy mm dd):";
cin>>year;
cin>>month;
cin>>day;
if((year/100)&&!(year/4)||year/400)
j=29;
switch (month)
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:i=31;
break;
case 2:i=j;
break;
case 4:
case 6:
case 9:
case 11:i=30;
break;
default:{
cout<<"Fault date:month"<<endl;
return 1;
}
if ((day>i)||(day<1))
{
cout<<"Fault date:days"<<endl;
return 1;
}
switch (month)
case 1:days=day;break;
case 2:days=31+day;break;
case 3:days=31+j+day;break;
case 4:days=31+j+31+day;break;
case 5:days=31+j+31+30+day;break;
case 6:days=31+j+31+30+31+day;break;
case 7:days=31+j+31+30+31+30+day;break;
case 8:days=31+j+31+30+31+30+31+day;break;
case 9:days=31+j+31+30+31+30+31+31+day;break;
case 10:days=31+j+31+30+31+30+31+31+30+day;break;
case 11:days=31+j+31+30+31+30+31+31+30+31+day;break;
case 12:days=31+j+31+30+31+30+31+31+30+31+30+day;break;
cout<<"days="<<days<<endl;
return 0;
}
编译错误报告
g++.exe "D:\yzf\c\lx2.cpp" -o "D:\yzf\c\lx2.exe" -I"D:\yzf\Dev-Cpp\include\c++" -I"D:\yzf\Dev-Cpp\include\c++\mingw32" -I"D:\yzf\Dev-Cpp\include\c++\backward" -I"D:\yzf\Dev-Cpp\include" -L"D:\yzf\Dev-Cpp\lib"
D:/yzf/c/lx2.cpp: In function `int main()':
D:/yzf/c/lx2.cpp:26: case label `2' not within a switch statement
D:/yzf/c/lx2.cpp:28: case label `4' not within a switch statement
D:/yzf/c/lx2.cpp:29: case label `6' not within a switch statement
D:/yzf/c/lx2.cpp:30: case label `9' not within a switch statement
D:/yzf/c/lx2.cpp:31: case label `11' not within a switch statement
D:/yzf/c/lx2.cpp:33: `default' label not within a switch statement
D:/yzf/c/lx2.cpp:46: case label `2' not within a switch statement
D:/yzf/c/lx2.cpp:47: case label `3' not within a switch statement
D:/yzf/c/lx2.cpp:48: case label `4' not within a switch statement
D:/yzf/c/lx2.cpp:49: case label `5' not within a switch statement
D:/yzf/c/lx2.cpp:50: case label `6' not within a switch statement
D:/yzf/c/lx2.cpp:51: case label `7' not within a switch statement
D:/yzf/c/lx2.cpp:52: case label `8' not within a switch statement
D:/yzf/c/lx2.cpp:53: case label `9' not within a switch statement
D:/yzf/c/lx2.cpp:54: case label `10' not within a switch statement
D:/yzf/c/lx2.cpp:55: case label `11' not within a switch statement
D:/yzf/c/lx2.cpp:56: case label `12' not within a switch statement
D:/yzf/c/lx2.cpp:25: break statement not within loop or switch
D:/yzf/c/lx2.cpp:27: break statement not within loop or switch
D:/yzf/c/lx2.cpp:32: break statement not within loop or switch
D:/yzf/c/lx2.cpp:45: break statement not within loop or switch
D:/yzf/c/lx2.cpp:46: break statement not within loop or switch
D:/yzf/c/lx2.cpp:47: break statement not within loop or switch
D:/yzf/c/lx2.cpp:48: break statement not within loop or switch
D:/yzf/c/lx2.cpp:49: break statement not within loop or switch
D:/yzf/c/lx2.cpp:50: break statement not within loop or switch
D:/yzf/c/lx2.cpp:51: break statement not within loop or switch
D:/yzf/c/lx2.cpp:52: break statement not within loop or switch
D:/yzf/c/lx2.cpp:53: break statement not within loop or switch
D:/yzf/c/lx2.cpp:54: break statement not within loop or switch
D:/yzf/c/lx2.cpp:55: break statement not within loop or switch
D:/yzf/c/lx2.cpp:56: break statement not within loop or switch