#include<iostream>
using namespace std;
class Date{
int year;
int month;
int day;
public:
void data(int d,int m,int y){
year=y;month=m;day=d;
}
void print(){
cout<<day<<" | "<<month<<" | "<<year<<endl;
}
void add(){
switch(month)
case 1:if(day==30)
{ day=1;month+=1; }
break;
case 2:if(year/4==0&&year/100!=0||year/400==0 && day==29)
{ day=1;month+=1;}
else if(day==28)
{ day=1;month+=1;}
break;
case 3:if(day==31)
{ day=1;month+=1;}
break;
case 4:if(day==30)
{ day=1;month+=1;}
break;
case 5:if(day==31)
{ day=1;month+=1;}
break;
case 6:if(day==30)
{ day=1;month+=1;}
break;
case 7:if(day==31)
{ day=1;month+=1;}
break;
case 8:if(day==31)
{ day=1;month+=1;}
break;
case 9:if(day==30)
{ day=1;month+=1;}
break;
case 10:if(day==31)
{ day=1;month+=1;}
break;
case 11:if(day==30)
{ day=1;month+=1;}
break;
case 12:if(day==31)
{ day=1;month+=1;}
break;
default:day+=1;break;
}
};
void main()
{
int y,m,d;
cout<<"day/month/year"<<endl;
cin>>d>>m>>y;
Date p;
p.data(d,m,y);
p.print();
p.add();
p.print();
}
我把switch里的变量了成month还是错的。。。
--------------------Configuration: Date - Win32 Debug--------------------
Compiling...
Date.cpp
H:\C++\Date.cpp(18) : error C2043: illegal break
H:\C++\Date.cpp(19) : error C2046: illegal case
H:\C++\Date.cpp(23) : error C2043: illegal break
H:\C++\Date.cpp(24) : error C2046: illegal case
H:\C++\Date.cpp(26) : error C2043: illegal break
H:\C++\Date.cpp(27) : error C2046: illegal case
H:\C++\Date.cpp(29) : error C2043: illegal break
H:\C++\Date.cpp(30) : error C2046: illegal case
H:\C++\Date.cpp(32) : error C2043: illegal break
H:\C++\Date.cpp(33) : error C2046: illegal case
H:\C++\Date.cpp(35) : error C2043: illegal break
H:\C++\Date.cpp(36) : error C2046: illegal case
H:\C++\Date.cpp(38) : error C2043: illegal break
H:\C++\Date.cpp(39) : error C2046: illegal case
H:\C++\Date.cpp(41) : error C2043: illegal break
H:\C++\Date.cpp(42) : error C2046: illegal case
H:\C++\Date.cpp(44) : error C2043: illegal break
H:\C++\Date.cpp(45) : error C2046: illegal case
H:\C++\Date.cpp(47) : error C2043: illegal break
H:\C++\Date.cpp(48) : error C2046: illegal case
H:\C++\Date.cpp(50) : error C2043: illegal break
H:\C++\Date.cpp(51) : error C2046: illegal case
H:\C++\Date.cpp(53) : error C2043: illegal break
H:\C++\Date.cpp(54) : error C2047: illegal default
H:\C++\Date.cpp(54) : error C2043: illegal break
执行 cl.exe 时出错.
Date.obj - 1 error(s), 0 warning(s)