Hi, I'm making a code that calculates the number of days between two dates. If you punch in 1 for month and 5 for days, and you punch in 2 for month and 1 for day, it should say "27 days between these two dates".
Right now the problem I have is that calculation. My code can record the day/month but doesn't know how to find the difference of days between those two dates.
I believe this is where my problem is
for (int i = inputMonth1; i < inputMonth2; ListMonth[MONTH_LENGTH]++, ListMonth + DifferenceBetweenDays);
cout << ListMonth[MONTH_LENGTH];
This is my entire code
#include <iostream>
using namespace std;
const int MONTH_LENGTH = 12;
int MinusOne(int);
int DifferenceDays(int);
int Date1;
int ListMonth [MONTH_LENGTH] = {30, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int Month1;
int Month2;
int inputDay1;
int inputDay2;
int main()
{
int inputMonth1;
int inputMonth2;
int Day1;
int Day2;
int DifferenceDay1;
int DifferenceDay2;
int DifferenceDay3;
cout << "This program calculates the days between two dates" << endl;
cout << "Enter the month (1-12)" << endl;
cin >> inputMonth1;
Month1 = MinusOne(inputMonth1); //This is so if I enter 5 for the month, my program won't identify it as 6.
cout << ListMonth[Month1] << "days in month " << inputMonth1 << endl;
cout << "Enter the day of the month" << endl;
cin >> inputDay1;
cout << "Enter the month (1-12)" << endl;
cin >> inputMonth2;
Month2 = MinusOne(inputMonth2);
cout << ListMonth[Month2] << endl;
cout << "Enter the day of the month" << endl;
cin >> inputDay2;
DifferenceDay1 = ListMonth[Month1] - inputDay1; //Adding these two together, then adding it between the months to find days
DifferenceDay2 = ListMonth[Month2] - inputDay2;
DifferenceDay3 == DifferenceDay1 + DifferenceDay2;
for (int i = inputMonth1; i < inputMonth2; ListMonth[MONTH_LENGTH]++, ListMonth + DifferenceDay3);
cout << ListMonth[MONTH_LENGTH];
//I'm hoping that if I enter 3 for month1 and 5 for day1 (for example) and 5 for month2 and 6 for day2,
/*it'll add DifferenceDay3 with the number of days from the month(s) in between those two dates, in this case
50 + 30 and that should get 80 days between from two dates*/
return 0;
}
int MinusOne(int inputMonth)
{
int Month;
Month = (inputMonth - 1);
return Month;
}
*I added green text to make it easier to know what some of my code does.
Thanks!