about-text

SoftOSet is the most remarkable programming site. SoftOSet provides the fresh conceptual and professional programs, articles, books, and other interesting and technical writings. SoftOSet is the most reliable programming site to learn the programs and the basics of the popular programming languages. SoftOSet is the hub of the informative and research based articles.

C++ Program to find Number of Days in Month

 

C++ program can be so efficient to inform you that how many days in the particular month of any year. You will probably know that C++ is very efficient and flexible language and these types of mathematical calculation can easily be performed or implemented in C++.


C++ Program on Execution


So, let’s start our work we will develop such a C++ program which on execution will ask the user to enter the month and year to find the number of days in the month. User will be prompted to enter the month and the year one by one. On putting these to parameters the user will finally get the number of days of the requested month.

 

Back End Programming


At back end we will make a main function of our program and declare three integer type variables days, month and year. We will take the input from user using the input statements cin>>month; and cin>>year. Then using these month and year we will use some conditional operators to clear our way.



 

Conditional Operators used


Ø  If year is leap and month is February then days will be 29, else for every other year days of February will be 28.

Ø  If month is January, March, May, July, August, October or December, the number of days will be 31.

Ø  For all other cases the months will have 30 days.

We have to just convert this logic into the C++ statements.

 

Code

 

//date 1 february 2019;

//program to find the number of days in a month

#include<iostream>

using namespace std;

int main()

{

            int year,month,days;

            cout<<"Enter the Month\n"<<endl;

            cin>>month;

           

                        cout<<"Enter the Year\n"<<endl;

            cin>>year;

           

            if(month==4||month==6||month==9||month==11)

            {

                        cout<<"There are 30 Days in the month no "<<month<<" of "<<year<<endl;

            }

            else if(month==2)

            {

                        if(year%4==0)

                        cout<<"There are 29 Days in the month no "<<month<<" of "<<year<<endl;

                        else

                                    cout<<"There are 28 Days in the month no "<<month<<" of "<<year<<endl;

            }

            else if(month==1||month==3||month==5||month==7||month==8||month==12)

            {

                        cout<<"There are 31 Days in the month no"<<month<<" of "<<year<<endl;

            }

            else

            cout<<"There are only Twelve Months in"<<year<<"\nAnd"<<month<<"is not any Month of "<<year<<endl;

            return 0;

}

 

 

Output


The sample run of this program will yield the following output.

 

 

 

 

 

 

 

 

If you have any problem regarding to this code or you have any type of problem with any other code. Please inform us we will try our level best to solve error for you. That’s it.



Thanks for learning from this site.


Post a Comment

Feel Free to Comment Us

Previous Post Next Post

Recents