Okay, I've tried everything I can think of including couts all over the place to see what my values looks like and I'm out of ideas, so I'll see if anyone else can figure it out.
For starters, I'm using Dev-C++ 4.9.9.2, though I doubt it matters for this.
I have a simple Date class in Date.h and Date.cpp. I'm including <string> and <cstdlib>.
Here is my constructor:
Code:
Date::Date()
{
month = 1;
day = 1;
year = 1900;
}
Here is the function I suspect is causing trouble:
Code:
string getDate() const;
Code:
string Date::getDate() const
{
char m[2], d[2], y[4];
string date;
// Convert the date fields to strings.
itoa( month, m, 10 );
itoa( day, d, 10 );
itoa( year, y, 10 );
// Assemble the date fields.
if( month < 10 )
date += "0";
date += m;
date += "/";
if( day < 10 )
date += "0";
date += d;
date += "/";
date += y;
return date;
}
Currently, this is the only code left in main, I have commented everything else out:
Code:
static Date currentDate;
cout << currentDate.getMonth() << endl;
cout << currentDate.getDay() << endl;
cout << currentDate.getYear() << endl;
cout << currentDate.getDate();
And this is the output I'm getting:
1
1
1900
1/0/1900
also If I change the day in the default constructor such as month = 10; day = 10;
the output becomes:
10
10
1900
//1900
If anyone knows whats up let me know please.