Problem with display user inputted Month, Day, Year using classes

My Date (Month,Day,Year) program will not display the month as a string for the months of April through December if inputted.
For example if I enter 3 for the month, and 12 for the day, and 2017 for the year... The program will display this just fine

//Output
3/12/2017
March 12, 2017
12 March 2017

This output will work if I choose 1-3 for the month (January through March).
As soon as I use anything other than those 3 months it will produce nothing for the month when displaying the Non (M/DD/YYYY) notations.

So if I used 12 for the month of December, and 25 for the day, and 2017 for the year, the output would look like..
//Output
12/25/2017
25, 2017
25 2017


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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <iostream>
#include <iomanip>
#include <string>
#include "Data.h"
using namespace std;

//function prototypes
void GetMonth (int);
void GetDay (int);
void GetYear (int);
void ShortNotationFunc();
void MonthFirstFunc();
void DayFirstFunc();

int main ()
{
	int Month, Day, Year;
	Date date;

	cout << "In the following user prompts, you will enter a month, day, and year" << endl;
	cout << "Please enter the month (1-12): ";
	cin >> Month;
	while (Month < 1 || Month > 12)
	{
		cout << "Invalid month! Enter (1-12) only!" << endl;
		cin.clear();
		cin.ignore();
		cin >> Month;
	}

	date.GetMonth(Month);

	cout << "Please enter the day (1-31): ";
	cin >> Day;
	while (Day < 1 || Day > 31)
	{
		cout << "Invalid day! Enter (1-31) only!" << endl;
		cin.clear();
		cin.ignore();
		cin >> Day;
	}

	date.GetDay(Day);

	cout << "Please enter the year: ";
	cin >> Year;
	while (Year < 1800 || Year > 2200)
	{
		cout << "Invalid year! Enter (1800-2200) only!" << endl;
		cin.clear();
		cin.ignore();
		cin >> Year;
	}
	date.GetYear(Year);

	cout << "\nDATE" << endl;
	cout << "____" << endl;
	cout << "1. ";
	date.ShortNotationFunc();
	cout << "2. ";
	date.MonthFirstFunc();
	cout << "3. ";
	date.DayFirstFunc();

	system("pause");
	return 0;
}


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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#ifndef DATE_H
#define DATE_H
#include <iostream>
using namespace std;

class Date
{
private:
	int Month, day, year;
	string month;

public:
	void GetMonth (int M) {
		if (M == 1)
			month = "January";
		else if (M == 2)
			month = "February";
		else if (M == 3)
			month = "March";
		else if (M == 4)
			month == "April";
		else if (M == 5)
			month == "May";
		else if (M == 6)
			month == "June";
		else if (M == 7)
			month == "July";
		else if (M == 8)
			month == "August";
		else if (M == 9)
			month == "September";
		else if (M == 10)
			month == "October";
		else if (M == 11)
			month == "November";
		else if (M == 12)
			month == "December";

			Month = M;
	}

	void GetDay (int D) {
		day = D;}

	void GetYear (int Y) {
		year = Y;}

	void ShortNotationFunc (){
		cout << Month << "/" << day << "/" << year << endl;
	}

	void MonthFirstFunc (){
		cout << month << " " << day << ", " << year << endl;
	}

	void DayFirstFunc () {
		cout << day << " " << month << " " << year << endl;
	}

};

#endif 
Last edited on
In your main file you don't need the function prototypes since you are including the Date.h file and you are setting it there.

You are using get functions yet they are not returning anything you are setting which can be confusing to others. You might be better off using a switch instead of if-else if statements.
Topic archived. No new replies allowed.