[C++] Nhập vào ngày hôm nay. Xuất ra hôm sau là ngày nào?
05:53
Đề: Nhập vào ngày hôm nay. Xuất ra hôm sau là ngày nào
#include<iostream>
using namespace std;
struct Date{
int day;
int month;
int year;
};
bool checkLeapyear(int year){
if(year%4==0 && year%10!=0) return true;
else return false;
};
int checkMonth(int month){
switch(month){
case 1: case 3: case 5: case 7: case 8: case 10:
return 1;
case 4: case 6: case 9: case 11:
return 2;
case 2:
return 3;
}
}
main(){
Date Date;
cout<<("Enter Data:\n");
cout<<("Day: ");
cin>>Date.day;
cout<<("Month: ");
cin>>Date.month;
cout<<("Year: ");
cin>>Date.year;
if(Date.day==31 && (checkMonth(Date.month)==1)){
Date.day=1;
Date.month++;
};
if(Date.day==30 && (checkMonth(Date.month)==2)){
Date.day=1;
Date.month++;
};
if(Date.day==28 && (checkMonth(Date.month)==3) && (checkLeapyear(Date.year)==false)){
Date.day=1;
Date.month++;
};
if(Date.day==29 && (checkMonth(Date.month)==3) && checkLeapyear(Date.year)==true){
Date.day=1;
Date.month;
};
if(Date.day==31 && Date.month==12){
Date.day=1;
Date.month=1;
Date.year++;
};
system("cls");
cout<<"THE NEXT DAY IS "<<Date.day<<" / "<<Date.month<<" / "<<Date.year;
}
#include<iostream>
using namespace std;
struct Date{
int day;
int month;
int year;
};
bool checkLeapyear(int year){
if(year%4==0 && year%10!=0) return true;
else return false;
};
int checkMonth(int month){
switch(month){
case 1: case 3: case 5: case 7: case 8: case 10:
return 1;
case 4: case 6: case 9: case 11:
return 2;
case 2:
return 3;
}
}
main(){
Date Date;
cout<<("Enter Data:\n");
cout<<("Day: ");
cin>>Date.day;
cout<<("Month: ");
cin>>Date.month;
cout<<("Year: ");
cin>>Date.year;
if(Date.day==31 && (checkMonth(Date.month)==1)){
Date.day=1;
Date.month++;
};
if(Date.day==30 && (checkMonth(Date.month)==2)){
Date.day=1;
Date.month++;
};
if(Date.day==28 && (checkMonth(Date.month)==3) && (checkLeapyear(Date.year)==false)){
Date.day=1;
Date.month++;
};
if(Date.day==29 && (checkMonth(Date.month)==3) && checkLeapyear(Date.year)==true){
Date.day=1;
Date.month;
};
if(Date.day==31 && Date.month==12){
Date.day=1;
Date.month=1;
Date.year++;
};
system("cls");
cout<<"THE NEXT DAY IS "<<Date.day<<" / "<<Date.month<<" / "<<Date.year;
}