Class dayType program always starts me on Monday

/*
I have fixed my problem with the overloaded member functions but when I run my program and choose a day to start off with, no matter what day I choose(Friday for example) it starts me off on Monday. My program adds the number of days(when prompted to do so) just fine but it always starts me on Monday. Does anyone see anything wrong/missing from my program that would cause Monday to be the starting no point no matter what day I choose? This is my first program this complex so any help/hints would be greatly appreciated.
*/

I am having trouble with a program I'm working on. I keep getting these errors:
error C2511: 'void dayType::printDay(void)' : overloaded member function not found in 'dayType'.
error C2511: 'int dayType::prevDay(int)' : overloaded member function not found in 'dayType'.

This is my first time writing a program this complex so any help/hints/suggestions would be greatly appreciated. These are the directions for the program I am trying to write:
Design and implement a class dayType that implements the day of the week in a program. The class dayType should store the day, such as Sun for Sunday. The program should be able to perform the following operation on objects of the type dayType:
Set the day
Print the day
Return the day
Return the next day
Return the previous day
Update the day, stored in a dayType object , by adding certain days to it. For example, if the day is Monday and you add 4 days, the updated day is Friday. Similarly, if the day is Tuesday, and you add 13 days, the updated day is Monday.
Write the main program to test the dayType class, you have to test all the functions in the class design.
Here is my work:

Header
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


#ifndef DAY_TYPE_H
#define DAY_TYPE_H


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

using namespace std;

/******* Class dayType Specification ********/

class dayType
{
	
	private:
		string days[7];
		string currentDay;
		int numDays;

	public:

		void setDay(string newDay);
		void printDay() const;
		int showDay(int& day);
		int nextDay(int day);
		int prevDay(int day) const;
		int calcDay(int day, int numDays);

		dayType()
		{
			days[0] = "Sunday";
			days[1] = "Monday";
			days[2] = "Tuesday";
			days[3] = "Wednesday";
			days[4] = "Thursday";
			days[5] = "Friday";
			days[6] = "Saturday";
			currentDay = days[0];
			numDays = 0;
		};
		~dayType();
	
};

#endif

Implementation File
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
102
103
#include "Header.h"


void dayType::setDay(string newDay)
{
   currentDay = newDay;
}

void dayType::printDay()
{
   cout << "Day chosen is " << currentDay << endl;

}

int dayType::showDay(int& day)
{
   return day;
}

int dayType::nextDay(int day)
{
	day = day++;

	if (day > 6)
		day = day % 7;

	switch (day)
	{
	case 0: cout << "The next day is Sunday";
		break;
	case 1: cout << "The next day is Monday";
		break;
	case 2: cout << "The next day is Tuesday";
		break;
	case 3: cout << "The next day is Wednesday";
		break;
	case 4: cout << "The next day is Thursday";
		break;
	case 5: cout << "The next day is Friday";
		break;
	case 6: cout << "The next day is Saturday";
		break;
	}
	cout << endl;
	return day;
}
	
int dayType::prevDay(int day)
{
	day = day--;

	switch (day)
	{
	case -1: cout << "The previous day is Saturday.";
		break;
	case 0: cout << "The previous day is Saturday.";
		break;
	case 1: cout << "The previous day is Saturday.";
		break;
	case 2: cout << "The previous day is Saturday.";
		break;
	case 3: cout << "The previous day is Saturday.";
		break;
	case 4: cout << "The previous day is Saturday.";
		break;
	case 5: cout << "The previous day is Saturday.";
		break;
	default: cout << "The previous day is Saturday.";
	}

	cout << endl;
	return day;

}

int dayType::calcDay(int addDays, int numDays)
{
	addDays = addDays + numDays;
	if (addDays > 6)
		addDays = addDays % 7;
	switch(addDays)
	{
	case 0: cout << "The calculated day is Sunday.";
		break;
	case 1: cout << "The calculated day is Monday.";
		break;
	case 2: cout << "The calculated day is Tuesday.";
		break;
	case 3: cout << "The calculated day is Wednesday.";
		break;
	case 4: cout << "The calculated day is Thursday.";
		break;
	case 5: cout << "The calculated day is Friday.";
		break;
	case 6: cout << "The calculated day is Saturday.";
		break;
	default: cout << "Not valid choice.";
	}
	cout << endl;
	return addDays;
}


Main
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
102
  #include <iostream>  
#include <string>  
#include "Header.h"


using namespace std;  
void showSelections();

int main()  
{  
	dayType userDay;
	int currentDay; 
	int addDays;
	int test;
	string day;
	

	do
	{
		test = 0;
		showSelections();
		cin >> currentDay;
		cout << endl;

		if (currentDay = 0)
		{
			userDay.setDay("Sunday");
		}
		else if (currentDay = 1)
		{
			userDay.setDay("Monday");
		}
		else if (currentDay = 2)
		{
			userDay.setDay("Tuesday");
		}
		else if (currentDay = 3)
		{
			userDay.setDay("Wednesday");
		}
		else if (currentDay = 4)
		{
			userDay.setDay("Thursday");
		}
		else if (currentDay = 5)
{
			userDay.setDay("Friday");
		}
		else if (currentDay = 6)
		{
			userDay.setDay("Saturday");
		}
		else if (currentDay = 9)
		{
			cout << "Exiting...";
			return 0;
		}
		else
		{
			cout << "Not a valid choice." << endl;
			test = -37;
		}
	}
	
	while (test < 0);
	userDay.printDay();
	cout << endl;

	userDay.showDay(currentDay);
	cout << endl;
	userDay.nextDay(currentDay);
	cout << endl;
	userDay.prevDay(currentDay);
	cout << endl;

	cout << "Enter the number of days to add: " << endl;
	cin >> addDays;
	cout << endl;

	userDay.calcDay(currentDay, addDays);
	cout << endl;

	cout << endl << endl;
	system("pause");
	return 0;
}

// Function to display weekday selections.
void showSelections()
{
	cout << "*****Please enter a day of the week*****" << endl;
	cout << "0 for Sunday" << endl;
	cout << "1 for Monday" << endl;
	cout << "2 for Tuesday" << endl;
	cout << "3 for Wednesday" << endl;
	cout << "4 for Thursday" << endl;
	cout << "5 for Friday" << endl;
	cout << "6 for Saturday" << endl;
	cout << "9 to exit" << endl;


}


Any help would be greatly appreciated.
Last edited on
You forgot const in function definitions:
void dayType::printDay() const
Thank you very much for bringing that to my attention. I feel pretty dumb for missing that but I greatly appreciate the help. I was able to get the program to run once I added the const but I got another error because of this~dayType(); so I took it out and it ran. The problem I am having now is that I choose a day, but no matter what day I choose it says Monday, any hints?
Last edited on
1) day = day++; ← this is illegal. It invokes undefined behavior. If you want to increment number of days, simple ++day; would suffice. Same for decrement.

2) if (currentDay = 0) ← sets currentDay to 0 and then checks if its value is true. As 0 is false it skips it, but next assigment (1 or monday) will yield true. Use == for comparison.

Turn on compiler warnings. It should watn you about both problems:
warning: operation on 'day' may be undefined [-Wsequence-point]|
warning: suggest parentheses around assignment used as truth value [-Wparentheses]|
Last edited on
Thank you very much for you help. I messed with my program and was able to fix all the issues that you pointed out. Thanks!
Topic archived. No new replies allowed.