### converter help

please i need to know if this code will work well for conversion of Celsius to Fahrenheit>...................please i need immediate help
please note this code is not all that complete
 ``1234567891011121314151617`` ``````#include using namespace std; double far(double a,double b,double c,double d); { double f; f+(a*b/c)+d; a=9,c=5,d=32; return(f); } int main(); { double b; cout<<"whats your celcius value"; cin>>b; cout<<"your answer is "<
Last edited on
Why don't you test it to see if it works? Once you test it, you will see that in line 15, you are attempting to pass variables that don't exist in the main() function (namely the variables called a, c, and d).
I think your function far() should be simplified to accept a single parameter. Something like this:
 ``12345`` ``````double far(double c) { double f = etc; // do the calculation here; return f; }``````

In the existing code, the lines are in the wrong order:
`a=9,c=5,d=32;` these values are assigned too late, after they have already been used. But really, you don't need individual variables, just put the numbers direct into the calculation. Be careful to use 9.0 and 5.0 so that floating-point rather than integer division will be done.
`f+(a*b/c)+d;`
Do you mean `f = ( a * b / c ) + d;` ?

`a=9,c=5,d=32;`
You may want to put this below `double f` instead since you will need these values before
`f+(a*b/c)+d;`

`far (a,b,c,d)`
Your way of calling the function is wrong, variables a, c and d is not defined in this scope, they are only defined in your function far

You can try your code now by just passing b as parameter and using the values in a, c and d inside the function
something like: `far ( , b, , ); `
Thanks a lot..... I had a feeling something was wrong...... So u are saying I don't need to call extra parameters..... And even if I do it should be like inside the int(main)?
The function does a specific task, it converts Celsius to Fahrenheit. That leads to a straightforward requirement, one input (the parameter) and one output (the returned value).

All the other numbers (32, 5, 9 etc.) belong inside the body of the function. How you do that is up to you, but there is definitely no need for them to be supplied as extra parameters.
Topic archived. No new replies allowed.