So my assignment is to write a complete program that prompts the user to input the radius of a circle(in main function),and calculates the diameter,circumference and area respectively(in three user-deļ¬ned functions),then prints those values to the screen(in main function).
I wrote this program and it runs but gives the wrong answers. For example, I enter a radius of 5 and it tells me the diameter is 00EF11CC. Why isn't it printing the right values?
(line 14): warning C4700: uninitialized local variable 'r' used
(line 21): warning C4700: uninitialized local variable 'r' used
(line 7): warning C4700: uninitialized local variable 'r' used
32:32: warning: the address of 'double diam(double)' will always evaluate as 'true' [-Waddress]
33:37: warning: the address of 'double circ(double)' will always evaluate as 'true' [-Waddress]
34:28: warning: the address of 'double area(double)' will always evaluate as 'true' [-Waddress]
that has nothing to do with your code in your methods, that's actually to do with your code in main:
This is simply the wrong way to call a function: cout << "The diameter is " << diam << endl;
it needs to be something like this: cout << "The diameter is " << diam(r) << endl;
After all, you've as the user for the radius so why don't you actually use it? :)