Advice

I have this function that is supposed to calculate the day depending on the number. i.e. If today is Sunday, and I add 15, it should return Monday. Problem is I have no idea how to approach this mathematically, should I use an enum type? Am I even on the right track?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
class dayType
{
public:
	void setDay(string);
	void printDay() const;
	string returnDay() const;
	string returnNext() const;
	string returnPrevious() const;
	string calculateDay(int);
	dayType();
private:
	string day;
};




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
string dayType::calculateDay(int num)
{
	switch(num % 10)
	{
	case 1:
		return returnNext();
		break;
	case 2:
		break;
	case 3:
		break;
	case 4:
		break;
	case 5:
		break;
	case 6:
		break;
	case 7:
		return returnDay();
	case 8:
		return returnPrevious();
	default:
		cout<<"Default"<<endl;
		return NULL;
	}
}
Try using modulus and an integer. Sunday is 0, monday is 1, etc to 7. Then add a number of days to it, and take the modulus (remainder) over 7.
Topic archived. No new replies allowed.