for month 2, it won't let me print the correct days

–1 vote
asked Feb 2 by anonymous
#include <iostream>
using namespace std;

int main()
{
    int year, month;
    cout << "Enter year: " << endl;
    cin >> year;
    cout << "Enter month: " <<endl;
    cin >> month;
    if (month == 1)
    {
        cout << "31 days";
    }
    else if (month == 2)
    {
        {
            if (year % 4)
            {
                if (year % 4)
                {
                    cout << "Common";
                }
                else
                {
                    cout << "Leap";
                }
            }
            else if (year % 100)
            {
                if (year % 100)
                {
                    cout << "Leap";
                }
                else
                {
                    cout << "Common";
                }
            }
            else if (year % 400)
            {
                if (year % 400)
                {
                    cout << "Common";
                }
                else
                {
                    cout << "Leap";
                }
            }
            else
            {
                cout << "Leap";
            }
        }
                        if ("Common")
                        {
                            cout << "28 days";
                        }
                        else
                        {
                            cout << "29 days";
                        }
    }
...
    else if (month == 12)
    {
        cout << "31 days";
    }
    return 0;
}

2 Answers

0 votes
answered Feb 4 by anonymous
U should write yr%4=0
U should tell how much remainder u want
0 votes
answered Feb 4 by SHIFAT
Do this for month 2. You will find your mistake by looking at it. You havent give any value to "if" condition to compare.

else if (month == 2)
    {
        
            if ((year % 4==0 && year % 100 !=0)|| year % 400==0)
            {
                    cout << "Leap";
                    cout << " 29 days";
            }
            else
            {
                cout << "Common";
                cout << "28 days";
            }

    }
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...