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
Post a Comment