Hello, I'm working on a homework assignment for my comp sci class and this error: "..\src\a4q1.cpp:38:52: warning: the address of 'int dayOfWeek(int, int, int)' will always evaluate as 'true' [-Waddress]" keeps coming up. I'm trying to get a function in the program to display a number that represents the day of the week based on the date that the user inputs. This is my code:
#include <iostream>
using namespace std;
int dayOfWeek (int day, int month, int year)
{ int d;
int m;
int y;
int y0;
int x;
int m0;
int d0;
y0 = y - (14 - m)/12;
x = y0 + y0/4 - y0/100 + y0/400;
m0 = m + 12 * ((14 - m)/12) - 2;
d0 = (d + x + (31 * m0)/12) % 7;
return d0;
}
int main() {
int d;
int m;
int y;
cout << "Please enter a day: ";
cin >> d;
cout << "Please enter a month: ";
cin >> m;
cout << "Finally, please enter a year: ";
cin >> y;
cout << "The day of the week that date was: " << dayOfWeek << endl;
}
cout << "The day of the week that date was: " << dayOfWeek << endl;
you do not call function dayOfWeek. The syntax of calling function is
function_name( argument_list )
So in your statement above you use operator << with operand dayOfWeek. In this expression function name is implicitly converted to a pointer to the function and it is always non-zero. So the compiler reports the warning.