Help with Functions!!!

Can someone help me with my code, I keep having issues in several lines.
This is what I wanted to accomplish.

MAIN FUNCTION () : This function will call the functions below.
Function #1: displays menu
Function #2: converts celsius to fahrenheit
Function #3: converts fahrenheit to celsius
Function #4: displays result
Function #5 if desired handles error checking
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
 #include <iostream>
using namespace std;

void programOverview ();
char getScale ();
float getDegree ();
float convertFtoC (float);
float convertCtoF (float);
void getResults ();

int main ()
{
  cout.precision (2);
  programOverview ();
  float degree = getDegree ();
  char scale = getScale();

  if (scale == 'F')
    {
      convertFtoC(degree);
    }
  else if (scale == 'C')
    {
      convertCtoF(degree);
    }
  else
    cout << "I'm Sorry. That isn't a valid input" << endl;

  getResults();

  return 0;
}

//Explains what the program will do 
void programOverview ()
{
  cout << "Hello! Welcome to F to C Converter" << endl;
  cout<< " This program will convert a temperature in"<< endl;
  cout << "either Fahrenheit or Celsius." << endl;
}

//This function requires the user to either enter Celsius or Fahrenheit to be converted
char getScale ()
{
  char scale;
  cout << "Please type either C for Celsius or F for Fahrenheit:" << endl;
  cout << "F = Fahrenheit; C = Celsius)" << endl;
  cin >> scale;
  return scale;
}

//This function requires the user to enter the temperature in degrees
float getDegree ()
{
  float degree;
  cout << "Enter the temperature you wish to convert in degrees:" << endl;
  cin >> degree;
  return degree;
}

//This function converts Celsius to Fahrenheit
float convertCtoF (float Ctemp)
{
  float Ftemp;
  Ftemp = 1.8 * Ctemp + 32;
  return Ftemp;
}

//This function converts Fahrenheit to Celsius
float convertFtoC (float Ftemp)
{
  float Ctemp;
  Ctemp = (Ftemp - 32) / 1.8;
  return Ctemp;
}

//This function displays the results
void getResults (Ctemp, Ftemp)
  {
  cout << "Your temperature reading converts as follows:" << endl;
  cout << "Fahrenheit:" << Ftemp << endl;
  cout << "Celsius:" << Ctemp << endl;
}


Last edited on
Right off the bat, it appears you didn't correctly define the programOverview() function. Look at line 34-39. It doesn't look like you put the function's header in.
You need to remove "return 0" from line 85, it doesn't belong there.

Also Ftemp and Ctemp are not defined anywhere in the function getResults(), that is why you are getting the error messages at compile time.






Topic archived. No new replies allowed.