Help with my bool logic for date validation

Hey guys,
I have a problem I need some help with. I pretty much have the problem complete. My issue is regardless of which date I input its always defaulting to the values I have set in my constructor in my implementation file in the else statement. So the values always default to 3/15/2006 I think its something to do with the logic in my bool function but I may be incorrect. If someone can assist me with this that would be appreciated. Thank you guys

header
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
//date.h header
#include <iostream>
#include <string>
using namespace std;

enum DateFormat {numeric, standard, alternative};
const int MIN_YEAR = 1900;
const int MAX_YEAR = 2015;
const string monthStr [] =
{"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November",
"December"};
const int monthDays [] =
{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

class Date			// Class body and declartions
{
private: 
	int month;
	int day;
	int year;
	bool isDateValid (int m, int d, int y);
public:
	Date (int m, int d, int y); // 3 argument constructor
	void getValues();
	
}; // End of class declaration 


Last edited on
closed account (D80DSL3A)
At line 9 in your constructor: if (isDateValid(month, day, year)) month, day and year have not yet been initialized. You wantif (isDateValid(m, d, y)) instead.

Some issues with your isDateValid() function:
I think you want >= and <= in place of > and < everywhere.
Also, if the year is valid it will return true without checking month or day.
Last edited on
Hey fun2code. Thanks for your response. I tried your suggestion switched month, day, year to m,d,y and the output for my code is still the same. Am I doing something else wrong?


1
2
3
4
5
6
if (isDateValid(m, d, y))
	{
	month = m;
	day = d;
	year = y;
	}
I built the solution again and its doing opposite to my last post. Now all the the input gets past the validation regardless of what is entered.
Try with doing if (isDateValid (month, day, year))Then after have a look at this.


1
2
3
4
5
6
if (isDataValid (m, d, y))
{
month = m; // add these for the key of the program.
day= d;
year = y;
}


Try that.
Topic archived. No new replies allowed.