Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printing a function returns an unexpected value, why?

Tags:

c++

function

I am passing a value into a function to convert Celsius to Fahrenheit, but the console prints an error code which brings up nothing when I Google it.

// Function Declarations
float fToC(float degreesF = 32.0);

int main() {
    float fahrenheit = 10; 
    float centigrade = 10;

    centigrade = fToC(fahrenheit); 
    cout << "Freezing Point: " << fToC << "C" << endl;

    return 0;
}


// Function Defintions 
float fToC(float degreesF) {
    float degreesC = ((5.0 / 9.0)*(degreesF - 32));
    return degreesC;
}

This prints into the console:

Freezing Point: 00A31627C

What did I do wrong?

like image 841
Ben Jackson Avatar asked May 07 '16 03:05

Ben Jackson


1 Answers

It is because you are printing out the function and not centigrade.

cout << "Freezing Point: " << fToC << "C" << endl; in the console it is showing the memory address of the function.

You should do something like:

cout << "Freezing Point: " << centigrade << "C" << endl;

like image 196
sebenalern Avatar answered Oct 20 '22 20:10

sebenalern