/* 
 * Solution to Problem 3 (C++)
 * 11th Annual CS Programming Contest
 * WCU Dept of Math and CS
 * Copyright 2000 , All Rights Reserved
 *
 * Problem Description:  The user enters two dates from the keyboard.
 * This program outputs the number of days between the two dates.
 * (including the second date as one day if it differs fromt he first day).
 * Leap years are handled properly.
 *
 */


#include <iostream.h>


/* symbolic constants for months */
#define  JAN 1
#define  FEB 2
#define  MAR 3
#define  APR 4
#define  MAY 5
#define  JUN 6
#define  JUL 7
#define  AUG 8
#define  SEP 9
#define  OCT 10
#define  NOV 11
#define  DEC 12


/* this function returns true
 * if the arguement is indeed a 
 * leap year -
 * A year is a leap year if it is
 * divisible by 400 or if it is
 * divisible by four but not by 100.
 */

bool isLeapYear(int year)
{
  return (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0));
}


/* get the number of days in a whole year */
int daysInYear(int year)
{
  if ( isLeapYear(year) )
    return 366;
  else
    return 365;
}


/* get the number of days in a whole month of a certain year */
int daysInMonth(int month, int year)
{
  int ans;

  switch(month)
  {
  case JAN:
    ans = 31;
    break;
  case FEB:
    if (isLeapYear(year))
      ans = 29;
    else
      ans = 28;
    break;
  case MAR:
    ans = 31;
    break;
  case APR:
    ans = 30;
    break;
  case MAY:
    ans = 31;
    break;
  case JUN:
    ans = 30;
    break;
  case JUL:
    ans = 31;
    break;
  case AUG:
    ans = 31;
    break;
  case SEP:
    ans = 30;
    break;
  case OCT:
    ans = 31;
    break;
  case NOV:
    ans = 30;
    break;
  case DEC:
    ans = 31;
    break;
  }
  return ans;
}


int main()
{
  // variables fro the first date 
  int yOne, mOne, dOne;
  
  //varaibles fro the second date
  int yTwo, mTwo, dTwo;

  //days between the two dates
  int days = 0;

  cout << "Input the first date:" << endl;
  cin >> mOne >> dOne >> yOne;

  cout << "Input the second date:" << endl;
  cin >> mTwo >> dTwo >> yTwo;
  
  if ( yOne < yTwo )
  {
    //get days in rest of yOne
    while ( mOne <= DEC)
    {
      //get rest of days in mOne
      days += daysInMonth(mOne, yOne) - dOne;
      mOne++;
      dOne = 0;
    }

    //Now we are in the next year, so update 
    yOne++;
    mOne = JAN;
   
    //we need to count jan 1, so we start at jan 0.
    // see the line labeled A below.
    dOne = 0;   
    
    while ( yOne < yTwo )
    {
      days += daysInYear(yOne);
      yOne++;
    }

    cout << mOne << " " << dOne << " " << yOne << " " << days << endl;
    
  }


  if ( mOne < mTwo)
  {
    //get rest of days in mOne
    days += daysInMonth(mOne, yOne) - dOne; //A - see comment above

    mOne++;
    dOne = 0; //same reasoning as above - used in line labeled B
    
    while ( mOne < mTwo)
    {
      days += daysInMonth(mOne, yOne); //yOne == yTwo
      mOne++;
    }
    cout << mOne << " " << dOne << " " << yOne << " " << days << endl;
  }
  
  days += dTwo - dOne; //B - see above

  //output the difference
  switch (days)
  {
  case 0:
    cout << "There are no days between those dates" << endl;
    break;
  case 1:
    cout << "There is 1 day between those dates" << endl;
    break;
  default:
    cout << "There are " << days << " days between those dates" << endl;
  }
}

    
  
