Hello,
So I've been trying to figure out how to do this program. I know there are many mistakes. So I'm sorry about that.
The program will calculate and print out the total number of days between two dates. The accepted dates are between 1/1/1901 and 12/31/2099. The program should have no limitation that the first date must be earlier or later than the second date.
What I did was create a readDate function with three reference parameters which would validate the dates and print an error message if invalid. I also created a second function to calculate the total number of days, which is then returned.
I know I'm doing something wrong with the second function.
string readDate (int& m, int& d, int& y)
{
//bla bla
if (d < 0 || d > 31)
{
cout << "Sorry, day is invalid." << endl;
}
d = (y - 1901)*365 + (y - 1901)/4;
}
This snippet is a bit concerning. The way it reads to me is you have a number of days d, you check that d is between 0 and 31 inclusive, and then go on to recalculate d.
Why not just recalculate it and forget about deciding via the if statement that goes nowhere?
Is d the number of days or the day number, in which case the lower bound is 1 not 0.