Function program (Fahrenheit/Celsius Calc)

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
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.

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.


How would I take the respective function and cout? I attempted to do this in line 20 and line 23, but I must have done something wrong.
closed account (z0My6Up4)
float main(float){
at line 7 does not look right. If your program takes no arguments it should be int main( ).
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.

Topic archived. No new replies allowed.