My plusOneDay function doese not work

I have worked on this for the good part of the day, I even restarted from scratch, but I am working on each function one by one and I am unable to get day to change when I call plusOneDay.

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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <iostream>
using namespace std;
#include <string>

class DayOfTheWeek
{
public:
	
	void setDay(string);
	string getDay();
	void printDay() ;
	string plusOneDay();
	string minusOneDay();
	string addDays(int);
private:
	int day; 
	int toNumber(string);
	string toName(int);
}; 


int DayOfTheWeek::toNumber(string name)
{
	if (name == "Monday") return 0;
	if (name == "Tuesday") return 1;
	if (name == "Wednesday") return 2;
	if (name == "Thursday") return 3;
	if (name == "Friday") return 4;
	if (name == "Saturday") return 5;
	return 6;
}


string DayOfTheWeek::toName(int idx)
{
	
	idx = idx % 7;

	
	switch (idx)
	{
		case 0: return "Monday"; break;
		case 1: return "Tuesday"; break;
		case 2: return "Wednesday"; break;
		case 3: return "Thursday"; break;
		case 4: return "Friday"; break;
		case 5: return "Saturday"; break;
		default: return "Sunday"; break;
	}
}



void DayOfTheWeek::setDay(string day1)
{
	day = toNumber(day1);
}

string DayOfTheWeek::getDay() 
{
	return toName(day);
}

void DayOfTheWeek::printDay() 
{
	cout << getDay() << endl;
}

string DayOfTheWeek::plusOneDay()
{
	return toName(day+1);
}

string DayOfTheWeek::minusOneDay()
{
	return toName(day-1);
}

string DayOfTheWeek::addDays(int incr)
{
	int idx = day + incr;
	if (idx < 0) idx += 7;
	return toName(idx);
}

int main()
{
	DayOfTheWeek Monday;

	Monday.setDay("Monday");
	Monday.getDay();
	Monday.printDay();
	Monday.plusOneDay();
	Monday.printDay();

	cin.get();
	cin.get();

	return 0;

}
Problem found. You have a conflict on your functions. Your plusOneDay function returns a string, but does not change the day inside the class instance. So when you run print day it prints the value of the unchanged day. What you need to do is change you plusOne, minusOne to have day += 1; before the return and maybe even change them to void functions and remove the toName call inside them completely. That's why you have printDay.
Thanks. It worked, but I needed the Monday object to remain Monday. I realized all had to do was cout the plusOneDay to the screen to get my required result. Your answer however, gave me an answer to the use of assigments to get things done. Thanks again.
Topic archived. No new replies allowed.