Check the number of days past in an year on a Specific Date

08:25 0 Comments A+ a-

Problem:
The day of year is a number between 1 and 365 (January 1 is day 1) for a common (i.e. non leap) year. Today is 10th April which is day number 100. Write a Program that asks the user to enter month (in numeric) and date and displays the corresponding day number.
Solution:
# include <iostream> using namespace std; int main() { int month; int date; int days;  
cout<<"Enter the Month"<<endl; cin>>month; cout<<"Enter the Date"<<endl; cin>>date; if(month==1)
{
cout<<"The day number for"<<" "<<date<<"-"<<month<<" "<<"is"<<" "<<date<<endl;
} else if(month==2)
{ days=31+date; cout<<"The day number for"<<" "<<date<<"-"<<month<<" "<<"is"<<" "<<days<<endl; } else if(month==3)
{
days=59+date; cout<<"The day number for"<<" "<<date<<"-"<<month<<" "<<"is"<<" "<<days<<endl; } else if(month==4)
{ days=90+date; cout<<"The day number for"<<" "<<date<<"-"<<month<<" "<<"is"<<" "<<days<<endl; } else if(month==5)
{ days=120+date; cout<<"The day number for"<<" "<<date<<"-"<<month<<" "<<"is"<<" "<<days<<endl; } else if(month==6)
{ days=151+date; cout<<"The day number for"<<" "<<date<<"-"<<month<<" "<<"is"<<" "<<days<<endl; } else if(month==7)
{ days=181+date; cout<<"The day number for"<<" "<<date<<"-"<<month<<" "<<"is"<<" "<<days<<endl; } else if(month==8)
{ days=212+date; cout<<"The day number for"<<" "<<date<<"-"<<month<<" "<<"is"<<" "<<days<<endl; } else if(month==9)
{ days=243+date; cout<<"The day number for"<<" "<<date<<"-"<<month<<" "<<"is"<<" "<<days<<endl; } else if(month==10)
{ days=273+date; cout<<"The day number for"<<" "<<date<<"-"<<month<<" "<<"is"<<" "<<days<<endl; } else if(month==11)
{ days=304+date; cout<<"The day number for"<<" "<<date<<"-"<<month<<" "<<"is"<<" "<<days<<endl; } else if(month==12)
{ days=334+date; cout<<"The day number for"<<" "<<date<<"-"<<month<<" "<<"is"<<" "<<days<<endl; } else cout<<"Months not in range"<<endl;
return 0; }