adding the totals of functions in main

I am still learning the function calls and I seem to be stuck when trying to add other functions together. I just want to add what the function is returning but I don't know how to get around the parameters which seems to make it not work properly.

I just need the dayofweek var to work by adding all the rest of the functions. I feel very close but I just can't seem to get it.
thanks for any help

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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
 #include <iostream>
using namespace std;

bool isLeapYear(int);
int getCenturyValue(int);
int getYearValue(int);
int getMonthValue(int, int);


int main()
{
	char choice;
	int month, day, year;
	int dayofweek;

	do
	{
		cout << "Enter a date in the form month day year, eg 4 24 1939 \n";
		cin >> month >> day >> year;

		//loop to not allow imporper dates
		while (month > 12 || month < 0 || day >31 || day < 0 || year > 2018 || year < 0)
		{
			cout <<"Invalid date" << endl;
			cout << "Enter a date in the form month day year, eg 4 24 1939 \n";
			cin >> month >> day >> year;
		}
		isLeapYear(year);
		getCenturyValue(year);
		getYearValue(year);
		getMonthValue(month, year);

		// calculating the day of the week given the totals from other functions
		dayofweek = (day + getMonthValue(month,year) + getYearValue(year) + getCenturyValue(year))%7;
		
		// if statement to show day of week given the total
		if (dayofweek = 0)
			cout << month << "/" << day << "/" << year << "/" << " is a Sunday" << endl;
		else if (dayofweek = 1)
			cout << month << "/" << day << "/" << year << "/" << " is a Monday" << endl;
		else if (dayofweek = 2)
			cout << month << "/" << day << "/" << year << "/" << " is a Tuesday" << endl;
		else if (dayofweek = 3)
			cout << month << "/" << day << "/" << year << "/" << " is a Wednesday" << endl;
		else if (dayofweek = 4)
			cout << month << "/" << day << "/" << year << "/" << " is a Thursday" << endl;
		else if (dayofweek = 5)
			cout << month << "/" << day << "/" << year << "/" << " is a Friday" << endl;
		else if (dayofweek = 6)
			cout << month << "/" << day << "/" << year << "/" << " is a Saturday" << endl;
		
		// runs another day of week when user enters "Y/y"
		cout << "Do you want to simulate again? <Y or N>"; 
		cin >> choice;
	} while (choice == 'Y' || choice == 'y');
	cout << "Thanks for playing!" << endl;


	return 0;
}

//bool statment for leap year
bool isLeapYear(int year)
{
	bool LeapYear = false;
	LeapYear = ((year % 400 == 0) || ((year % 4 == 0) // leap year algorithm
		&& (year % 100 != 0)));

	return LeapYear;
}

//calculates the century value
int getCenturyValue(int year)
{
	int remainder;
	int centuryValue;

	// pulls the year the user enters
	year /= 100;	
	remainder = year % 4;	
	centuryValue = (3 - remainder) * 2;		

	return centuryValue;
}

//calculates the year value
int getYearValue(int year)
{
	int remainder, yearValue;

	//pulls the year the user enters
	year %= 100;
	remainder = year / 4;
	yearValue = remainder + year;

	return yearValue;
}

//calculates the month value
int getMonthValue(int month, int year)
{
	int monthValue;

	//uses the month the user enters
	//uses the leap year function
	switch (month)
	{
	case 1: if (isLeapYear(year))
			monthValue = 6;
			else monthValue = 0;
			break;
	case 2: if (isLeapYear(year))
			monthValue = 2;
			else monthValue = 3;
			break;
	case 3: if (isLeapYear(year))
			monthValue = 3;
			else monthValue = 3;
			break;
	case 4: if (isLeapYear(year))
			monthValue = 6;
			else monthValue = 6;
			break;
	case 5:	if (isLeapYear(year))
			monthValue = 1;
			else monthValue = 1;
			break;
	case 6: if (isLeapYear(year))
				monthValue = 4;
			else monthValue = 4;
			break;
	case 7:	if (isLeapYear(year))
				monthValue = 6;
			else monthValue = 6;
			break;
	case 8:	if (isLeapYear(year))
				monthValue = 2;
			else monthValue = 2;
			break;
	case 9:	if (isLeapYear(year))
				monthValue = 5;
			else monthValue = 5;
			break;
	case 10: if (isLeapYear(year))
				monthValue = 0;
			else monthValue = 0;
			break;
	case 11: if (isLeapYear(year))
				monthValue = 3;
			else monthValue = 3;
			break;
	case 12: if (isLeapYear(year))
				monthValue = 5;
			else monthValue = 5;	
	}	
		
	return monthValue;
} 
Never mind... I did some debugging and realized my data was not passing as it should through the if/else statements. I changed them to all switch instead and it works just fine. Glad I was able to solve before anyone posted (you never know how long it will take for a response... so I post a little early sometimes).
Last edited on
Topic archived. No new replies allowed.