Function returning a memory address?

Hey, I'm a tad perplexed as to why my code seems to be returning a memory address (I think, it's a hexadecimal value that changes every time I compile).

I'll link the code below and would thank you for your 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
#include <iostream>
#include <string>

using namespace std;

double dayOfWeek(int day, int month, int year)
{
	double dRes1 = 2 - year/100 + year/400;
	double dRes2 = 365.25 * year;
	double dRes3 = 30.6001 * (month + 1);
	int JDN = dRes1 + dRes2 + dRes3 + day + 1720994.5;

	int dayOfWeek = (JDN + 1) % 7;

	return 0;
}

int main()
{
	int day, month, year;

	cout << "Enter the day: ";
	cin >> day;

	cout << "Enter the month: ";
	cin >> month;

	cout << "Enter the year: ";
	(cin >> year).ignore();
	

	dayOfWeek(day, month, year);

	cout << dayOfWeek;

	cin.ignore();
	return 0;
}


Thanks a lot :)
Ed

EDIT: Don't worry, I sorted it.. xD!
Last edited on
Line 34 cout << dayOfWeek; - this isn't a function call. It just outputs the address of the function.

On the other hand, at line 32 you do have a function call, but don't do anything with the returned value.

You could do either
1
2
    double result = dayOfWeek(day, month, year);
    cout << result;

or simply
cout << dayOfWeek(day, month, year);

By the way, at line 15, the function always returns a value of zero, which is thus what you will see printed.
Last edited on
Cool, thanks for the explanation :) As I say, I did sort it but it's nice to know why it wasn't working!

Thanks a lot,
Ed
Topic archived. No new replies allowed.