not reading input

The problem I am getting is the date comes out as 0/0/0 I have poured over this and dont know what im doing wrong

//HEADER

#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

int year;
int month;
int day;
int CYear;
int CMonth;
int CDay;

class Date
{
public:
void setCYear( int year )
{
year = CYear;
}

int getCyear( int year)
{
return CYear;
}

void setCMonth( int month )
{
month = CMonth;
}

int getCmonth( int month)
{
return CMonth;
}

void setCDay( int day )
{
day = CDay;
}

int getCDay( int day)
{
return CDay;
}

};

//SOURCE CODE

#include <iostream>
#include "date.h"

using namespace std;


int main()
{
Date MyDate;

cout << "Please enter two digit month: ";
cin >> month;
MyDate.setCMonth( month );

cout << "Please enter two digit day: ";
cin >> day;
MyDate.setCDay( day );

cout << "Please enter four digit year: ";
cin >> year;
MyDate.setCYear( year );

cout << "Current date is:\n" << MyDate.getCmonth( month ) << "/" << MyDate.getCDay( day ) << "/" << MyDate.getCyear( year );

system("pause");

return 0;

}
Last edited on
Are you absolutely required to use classes for this assignment?
yes
I revised my code as below and it seems to be working now?

Header:

public:
void setCYear( int year )
{
CYear = year;
}

int getCYear()
{
return CYear;
}

void setCMonth( int month)
{
CMonth = month;
}

int getCMonth()
{
return CMonth;
}

void setCDay( int day )
{
CDay = day;
}

int getCDay()
{
return CDay;
}


};

Source File

cout << "Current date is:\n" << MyDate.getCMonth() << "/" << MyDate.getCDay() << "/" << MyDate.getCYear() << endl;
Topic archived. No new replies allowed.