Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Here is my problem description: Write a program to determine the number of days

ID: 3621410 • Letter: H

Question

Here is my problem description:

Write a program to determine the number of days setween any two dates from July 4, 1776 until November 4, 2010 inclusive. You must enre that the user enters valid dates. This means a valid year, valid month, and valid day of month.

Your program should start at beginning date( which must not be after the ending date), and count each day until the ending date.

The program should print out the month and year as it counts(but not the day). If you count a February that's in a leap year, add that to the output of the month.

The final output will be two items: number of days and number of leap years between dates.

I am having a lot of trouble with making sure that the dates the user enters are valid in relation to each other AND in relation to the problem. I have a function done to determine whether or not the date is actually possible according to the calendar, but I don't understand where to go from here.

Explanation / Answer

please rate - thanks

#include <iostream>
using namespace std;
bool validate(int,int,int);
int leap(int);

int main()
{string mth[12]={"January","February","March","April","May","June","July",
                "August","September","October","November","December"};
int daysinmonth[12]={31,28,31,30,31,30,31,31,30,31,30,31};               
int month,day,year,days;
int month2,day2,year2,leapyear=0,l;
bool valid;
do
{
   do
   {
     cout<<"enter month ";
     cin>>month;
     cout<<"enter day ";
     cin>>day;
     cout<<"enter year ";
     cin>>year;
     valid=validate(month,day,year);
     if(!valid)
         cout<<"invalid date ";
     }while(!valid);
     do
     {
     cout<<"enter ending month ";
     cin>>month2;
     cout<<"enter ending day ";
     cin>>day2;
     cout<<"enter ending year ";
     cin>>year2;
      valid=validate(month2,day2,year2);
     if(!valid)
         cout<<"invalid date ";
     }while(!valid);
if(year2<year||(year2==year&&month2>month)||(year2==year&&month2==month&&day2<day))
      cout<<"end date cannot be before start date ";  
}while(year2<year||(year2==year&&month2>month)||(year2==year&&month2==month&&day2<day));
     cout<<" The number of days between "<<month<<"/"<<day<<"/"<<year<<
           " and "<<month2<<"/"<<day2<<"/"<<year2<<" is: ";
   
    
     cout<<mth[month-1]<<" "<<year<<endl;
     days=daysinmonth[month-1]-day;
     if(month==2)
          {l=leap(year);
           if(l==1)
              {cout<<"went through leap year ";
              leapyear++;
              days++;
              }
           }   
    do
    {month++;
    if(month==13)
         {month=1;
          year++;
          l=leap(year);
          }
      cout<<mth[month-1]<<" "<<year<<endl;
     days+=daysinmonth[month-1];
      { if(l==1&&month==2)
              {cout<<"went through leap year ";
              leapyear++;
              days++;
              }
           }   
    }while(month!=month2||year!=year2);
    days=days-daysinmonth[month-1];
    days+=day2;
    cout<<"days: "<<days<<"    leap years: "<<leapyear<<endl;
system("pause");
}       
        
int leap(int year)
{int leapcode=0;
    if(year%4==0)
    {if(year%100!=0)
            leapcode=1;
       else
           if(year%400==0)
               leapcode=1;
       }
return leapcode;
}
bool validate(int month, int day,int year)
{
int feb;
    if (day <= 0)
        return 0;

    switch(month)
    {
        case 1 :
        case 3 :
        case 5 :
        case 7 :
        case 8 :
        case 10:
        case 12: if (day > 31)
                      return false;
                 else
                      return true;
        case 4 :
        case 6 :
        case 9 :
        case 11: if (day > 30)
                      return false ;
                 else
                      return true;
       
        case 2 : feb=28+leap(year);
                 if (day > feb)
                       return false;
                 else
                       return true;
    }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote