Ok, here is what I have for my compareDates() function in my class:

int Date::compareDates(int m, int d, int y)
{
	if((month < m) || (day < d) || (year < y))
		cout << "This date comes before previous valid date." << endl;
	else if((month == m) || (day == d) || (year == y))
		cout << "This date is the same as the previous valid date." << endl;
	else
		cout << "This date comes after previous valid date." << endl;

	return 0;
}

It keeps returning "This date is the same as the previous valid date". I'm assuming that it is initializing it to itself or what it just read in from the file. Any quick fixes?

Ok, here is what I have for my compareDates() function in my class:

int Date::compareDates(int m, int d, int y)
{
	if((month < m) || (day < d) || (year < y))
		cout << "This date comes before previous valid date." << endl;
	else if((month == m) || (day == d) || (year == y))
		cout << "This date is the same as the previous valid date." << endl;
	else
		cout << "This date comes after previous valid date." << endl;

	return 0;
}

It keeps returning "This date is the same as the previous valid date". I'm assuming that it is initializing it to itself or what it just read in from the file. Any quick fixes?

Why are you returning 0? If you always return the same thing, generally you should not return anything and it should be a void function. You should, when posting code, also post the CALL to the function, as this gives added information.

Here, though, the problem is visible even without the call. One, be careful regarding the difference between && and ||. && means "and", || means "or". So according to this line:

else if((month == m) || (day == d) || (year == y))

if the code gets this far, 1/1/1980 is the same as 5/1/1981 since the day is 1 for both.

But the logic is wrong for the entire function. Think about how you'd figure it out without programming. You'd check the year, then the month, then the day, in that order. Right now you have no order/precedence to your comparisons.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.