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

**Here is the assignment: Write a program to determine the number of days betwee

ID: 3621426 • Letter: #

Question

**Here is the assignment:

Write a program to determine the number of days between any two dates from
July 4, 1776 until now. Inclusive. You must ensure that the user enters valid dates.
This means a valid year, a valid month, and a valid day of the month.

Your program should then start at the 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 (NB: not the day).
If you count a February that is in a leap year, note that in the output.

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

**The areas that have 3 dots in a row indicate parts I wasn't sure how to write. It's only 2 areas and also not sure how to output the values at the end of the program (print total days and print # of leap years). Here is what I have and I would greatly appreciate any help:

#include

using namespace std;

//Main function
int main()
{

//Creating an array
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

int year = 0;
int GivenYear=0;
int GivenMonth=0;
int GivenDays = 0;
int EndDays = 0;
int MaxYear =0;
int MaxMonth =0;
int TotalDays = 0;
int TotalLeap = 0;

bool leap = false;
bool SameYear = false;
bool SameMonth = false;

int counter = 0;

year = GivenYear;

//special condition
if (GivenYear == MaxYear)
{
SameYear = true;

if (GivenMonth == MaxMonth)
{
SameMonth = true;
}
else
{

//subtract initial days of the first month from that months total days
//assuming you are counting the first day
//I.e. july 4th, you skip days 1 2 3, but since you are subtracting 4, add 1 back in
TotalDays = TotalDays - GivenDays + 1;
}
}

//create a loop for the first year
//note that month 1 lies in the 0th spot, etc.
counter = GivenMonth - 1;

while (counter <= 12 && year < MaxYear)
{

TotalDays = TotalDays + month[counter];
.
.
.
year++;
}

//this loop will spin through the years
//note that the last year i will handle separately, like i handled the 1st separately
while (year < MaxYear)
{

//flag for leap year
leap = 0;
counter = 0;

//inside loop will spin though the month
while (counter <= 12){

counter++;
TotalDays = TotalDays + month[2];

if (counter = 2)
{

//handles leap years
//recall that every "100" years is not a leap year, unless it can be also be divisible by 4
//1200, 1600, 2000, 2400, the only year that falls under this for you is 2000
//special leap year
if (year == 2000)
{

TotalDays++;
leap = 1;
TotalLeap++;
}

else if (year % 4 == 0 && year % 100 != 0){

TotalDays++;
leap = 1;
TotalLeap++;
}
}

if (counter == 1)
{

cout << "January" ;
}

if (counter == 2)
{
cout << "Febuary";

if (leap == 1)
{
cout << "leap year";
}

if (counter == 3)
{
cout << "March";
}

if (counter == 4)
{
cout << "April";
}

if (counter == 5)
{
cout << "May";
}

if (counter == 6)
{
cout << "June";
}

if (counter == 7)
{
cout << "July";
}

if (counter == 8)
{
cout << "August";
}

if (counter == 9)
{
cout << "September";
}

if (counter == 10)
{
cout << "October";
}

if (counter == 11)
{
cout << "November";
}

if (counter == 12)
{
cout << "December";
}

year++;

}
}

//to handle the last year

if (year == MaxYear)
{

if (SameYear == false)
{

counter = 0;
}

else
{

counter = GivenYear;
}

while (counter <= GivenMonth - 1)
{

TotalDays = TotalDays + month[counter];
.
.
.

}

now you need to subtract the days from the end month as you did at the first month

subtract initial days of the first month from that months total days

TotalDays = TotalDays - EndDays + 1
//assuming you are counting the first day
//I.e. july 4th, you skip days 1 2 3, but since you are subtracting 4, add 1 back in

print total days;
print # of leap years

Explanation / Answer

please rate - thanks

I gave up on yours did my own, sorry it's a little mess-I rushed

#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;
    }
}