Hi this code works and compiles without errors, the outptut is correct, but
under the date, I am getting a weird set of numbers. I think it has somthing
to do with the displayDate() function, but I am not sure. Do you know what is causing it?
Code:
#include <iostream>
using std::cout;
using std::endl;
using std::cin;
class Date
{
public:
Date( int tempDay, int tempMonth, int tempYear )
{
// check that number in constructor is not below zero
if ( tempDay < 0 )
{
tempDay = 0;
}
day = tempDay;
if ( tempMonth < 0 )
{
tempMonth = 0;
}
month = tempMonth;
if ( tempYear < 0 )
{
tempYear = 0;
}
year = tempYear;
}
int setDay ( int d )
{
day = d;
}
int setMonth ( int m )
{
month = m;
}
int setYear ( int y )
{
year = y;
}
int getDay()
{
return day;
}
int getMonth()
{
return month;
}
int getYear()
{
return year;
}
int displayDate ( void )
{
cout << "\nDATE: " << day << " / " << month << " / " << year << endl;
}
private:
int day;
int month;
int year;
};
// main function - driver //////////////////////////////////////////////////////
//
int main ( void )
{
Date d ( 0, 0, 0 );
// set values of members and display to screen
d.setDay(5);
cout << "Day is: " << d.getDay() << endl;
d.setMonth(11);
cout << "Month is: " << d.getMonth() << endl;
d.setYear(2006);
cout << "Year is: " << d.getYear() << endl;
// display date in correct fromat
cout << d.displayDate();
cin.get(); // freeze console window
return 0; // indicate program ended sucsessfuly
}
Output I get:
Day is: 5
Month is: 11
Year is: 2006
Year is: 5 / 11 / 2006
457000 // this number should not be here!!