Tech Study

C++ Program to Enter Month and Print Days.

Introduction

C++ program to enter month number and print number of days in month. I have used DEV-C++ compiler for debugging purpose. But you can use any C programming language compiler as per your availability.

#include<iostream>
using namespace std;

int main()
{
    int month;
    cout << "Enter month number (1-12):";
    cin >> month;

    if(month == 1)
    {
        cout << "Enter month : January " <<endl;
        cout << "No. of days : 31 days" <<endl;
    }
    else if(month == 2)
    {
        cout << "Enter month : February " <<endl;
        cout << "No. of days :  28 or 29 days" <<endl;
    }
    else if(month == 3)
    {
        cout << "Enter month : March " <<endl;
        cout << "No. of days :  31 days" <<endl;
    }
    else if(month == 4)
    {
        cout << "Enter month : April " <<endl;
        cout << "No. of days :  30 days" <<endl;
    }
    else if(month == 5)
    {
        cout << "Enter month : May " <<endl;
        cout << "No. of days :  31 days" <<endl;
    }
    else if(month == 6)
    {
        cout << "Enter month : June " <<endl;
        cout << "No. of days :  30 days" <<endl;
    }
    else if(month == 7)
    {
        cout << "Enter month : July " <<endl;
        cout << "No. of days :  31 days" <<endl;
    }
    else if(month == 8)
    {
        cout << "Enter month : August " <<endl;
        cout << "No. of days :  31 days" <<endl;
    }
    else if(month == 9)
    {
        cout << "Enter month : September " <<endl;
        cout << "No. of days :  30 days" <<endl;
    }
    else if(month == 10)
    {
        cout << "Enter month : October " <<endl;
        cout << "No. of days :  31 days" <<endl;

    }
    else if(month == 11)
    {
        cout << "Enter month : November " <<endl;
        cout << "No. of days :  30 days" <<endl;
    }
    else if(month == 12)
    {
        cout << "Enter month : December " <<endl;
        cout << "No. of days :  31 days" <<endl;
    }
    else
    {
        cout << "Invalid input! Please enter month number between (1-12).";
    }

    return 0;

}

Result

C++ program to enter month number and print number of days in month.
C++ program to enter month number and print number of days in month.

Here are some more c++ program for your practice :

C++ Program To Print Number Of Days In a Month Using Switch Case

Write C++ Multiplication Table Programs

TaggedC program to enter month number and print number of days in month.

Java Final keyword

Introduction : java final keyword The final keyword present in Java programming language is generally used for restricting the user. …

Read more

C++ Memory Management: new and delete

C++ Memory Management We know that arrays store contiguous and the same type of memory blocks, so memory is allocated …

Read more