Program to calculate the number of days from the beginning of the year to a date specified by the user through array in C++

Using Visual Studio 2015

===============================================================

#include<iostream>
using namespace std;
#include<conio.h>
void main()
{
 int day,month,totaldays;
 int days_in_a_month[12]={31,28,31,30,31,30,31,31,30,31,30,31};
 cout<<"Enter the month= ";
 cin>>month;
 cout<<"Enter the day (1 to 31) = ";
 cin>>day;
 totaldays=day;
 for (int i = 0;i < month - 1;i++)
 {
     totaldays+=days_in_a_month[i];
 }
 cout<<"Total number of days are "<<totaldays;
 _getche();
}

==========================================================================

Comments

Popular posts from this blog

Suppose you are given a square matrix of size n x n, write a program to determine if this is an identity matrix. 2D array

Program to create a multiplication table of a given number using while loop.

Program to find equal values using if statement in C++