trying out an inline function, not going to well...xD

I get a compile error saying; fahrenheit is not declared in the scope. I don't see how that works, anyone care to explain ^^ thanks

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>

using namespace std;

inline float calculate(float fahrenheit, float celsius)
{
    fahrenheit = ((celsius * 9) /5) + 32;
    return (fahrenheit);
}

int main()
{
    float celsius;
    float fahrenheit;
    cout << "please enter temp for celsius to be converted \n";
    cin >> celsius;
    float calculate(float);
    cout << "fahrenheit is... \n" << fagrenheit;
    return 0;
}


// new problem, why can I only use float as the return, "long" returns a massive num? :S
Last edited on
I should learn to type xD
I'm guessing your old problem was a misspelling of fahrenheit, then ;)

You can use 'long' if you want, but then you ought to have the parameters as longs also. Note that 'float' is a floating point type (numbers beyond the decimal point), whereas 'long' is an integral type (whole numbers only). If you want higher precision/larger floating point numbers, use 'double'.

Note also that if you use long, then you will be dividing integers, which is not a good idea in C++ as the results are truncated (the bit past the decimal point is chopped off, not rounded). Finally, bear in mind that 9, 5 and 32 are integer literals. 9.0f, 5.0f and 32.0f are float literals and 9.0, 5.0 and 32.0 are double literals.

-Xander
Hey, thanks Xander.

I understood the last part about the floats and doubles, the part about longs I didn't quite follow. Since they are truncated surely the only part left is the integer (actual number not parameter) is left? :S
Topic archived. No new replies allowed.