当前位置:网站首页>Enter the year, month, and determine the number of days

Enter the year, month, and determine the number of days

2022-07-04 07:04:00 cycy_ 0918

#include<iostream>
using namespace std;
int year,month;
// Correct year 
bool isRightYear(int year){
    
    if(year>=0&&year<=9999)
    return true;
    return false;
}
// The month is correct 
bool isRightMonth(int month){
    
    if(month>=1&&month<=12)
    return true;
    return false;
}
// Is the year a leap year 
bool isLeapYear(int year){
    
    if(year%400==0||(year%100!=0&&year%4==0))
    return true;
    return false;
}
// Month type 
int monthType(int month){
    
    int days;
    switch(month){
    
        case 1:case 3:case 5:case 7:case 8:case 10:case 12:
        days=31;break;
        case 4:case 6: case 9: case 11:
        days=30;break;
        case 2:
        if(isLeapYear(year))
        {
    
            days=29;break;
        }
        else{
    
            days=28;break;
        }
    }
    return days;
}
int main()
{
    
    cin>>year>>month;
    isRightYear(year);
    isRightMonth(month);
    cout<<monthType(month)<<endl;
    return 0;
}
原网站

版权声明
本文为[cycy_ 0918]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/185/202207040658138208.html