Need help calling functions

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
int determineDay(int month, int day, int year) {
	char slash_dummy;
	cout << "Enter your date of birth" << endl;
	cout << "format : month / day / year--> ";
	cin >> month >> slash_dummy >> day >> slash_dummy >> year;
	int monthEq;
	if (month == 1 || month == 2) {
		monthEq = month + 12;
	}
	else {
		monthEq = month;
	}
	int dayEq = day;
	int yearPrefix = year / 100;
	int yearEq = year % (yearPrefix * 100);
	int dayOfWeek = (day + ((13 * (monthEq + 1)) / 5) + yearEq + (yearEq / 4) + (yearPrefix / 4) + 5 * yearPrefix) % 7;
    return 0;
}


void printDayOfBirth(int day) {
   if (dayOfWeek == 0) {
   cout << "Saturday";
   }
   else if (dayOfWeek == 1) {
   cout << "Sunday";
   }
   else if (dayOfWeek == 2) {
   cout << "Monday";
   }
   else if (dayOfWeek == 3) {
   cout << "Tuesday";
   }
   else if (dayOfWeek == 4) {
   cout << "Wednesday";
   }
   else if (dayOfWeek == 5) {
   cout << "Thurday";
   }
   else {
   cout << "Friday";
   }
   return;
}

I want to call dayOfWeek into printDayOfBirth so that printDayOfBirth already knows its value. How do I do that? Nothing I try seems to work.
Last edited on
What the hell are you doing with the returns, who taught you to use them like that?
Excuse my friend here hes new to human interaction.

Return statements are used in functions to return some value depending on what you expect the function to do. A void function is not expected to return any values so it can be used to cout the day of birth depending on the parameters given. When you make a function an int, char, double, ect.. you must return that data type from that function. The function determineDay(); should be returning a value based on what you're doing inside of the function.

Take a look at this stuff and make sure you understand how functions work :)
http://www.cplusplus.com/doc/tutorial/functions/

Once you understand functions you can take a look into templates for more control
http://www.cplusplus.com/doc/tutorial/functions2/
Last edited on
Topic archived. No new replies allowed.