May 9, 2014 at 2:17pm UTC
I am attempting to write a program that converts Fahrenheit temperature into Celsius and vice versa. As stated in the title, I am attempting to do so by the use of two functions.
*I've only just started functions, any advice would be helpful.
Thank you!
This is what I currently have:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
#include <iostream.h>
float totalFahrenheit(float );
float totalCelsius (float );
float main(float ){
float temp;
char choice;
cout<<"Type in the temperature: " ;
cin>>temp;
cout<<"Press C to convert to Celsius and press F to convert to Fahrenheit: " ;
cin>>choice;
totalFahrenheit(temp);
totalCelsius(temp);
if (choice=='c' || choice=='C' ){
cout<<temp<<" degrees Fahrenheit converted to Celsius is: " <<totalCelsius(temp);
}
else if (choice=='F' || choice=='f' ){
cout<<temp<<" degrees Celsius converted to Fahrenheit is: " <<totalFahrenheit(temp);
}
}
float totalFahrenheit(float temp){
return ((9/5*temp)+(32));
}
float totalCelsius (float temp){
return ((temp-32)*(5/9));
}
Last edited on May 9, 2014 at 2:25pm UTC
May 9, 2014 at 2:29pm UTC
Did you have a question?
Lines 17-18 don't do anything. Well, they do call the respective function, but you're not doing anything with the result returned by the function.
Other than that, it looks reasonable.
May 9, 2014 at 2:53pm UTC
Delete lines 17-18.
Lines 20 and 23 are fine. They will call the respective function and the returned result will be printed.
+1 regarding flint 's comment about main.