有个程序,总是有一个错误,初学者,求指教!
#include<iostream.h>class Date
{
private:
int day,month,year;
public:
Date(int d,int m,int y)
{
day=d;
month=m;
year=y;
cout<<day<<"/"<<month<<"/"<<year<<endl;
};
void add()
{
if(month>0 && month<13)
{
if(month==1||month==3||month==5||month==7||month==8||month==10)
{
if(day>0 && day<31)day++;else if(day==31){day=1;month++;}}
else if(month==12)
{
if(day>0 && day<31)day++;else if(day==31){day=1;month=1;year++;}}
else
{
if(day>0 && day<31)day++;else if(day==31){day=1;month++;}
}
cout<<day<<"/"<<month<<"/"<<year<<endl;
};
}
int main()
{
Date date1(4,6,2015);
date1.add();
}