Converting from Fahrenheit to celsius.

This is what I have so far...

#include <iostream>
#include <iomanip>
using namespace std;

void programOverview ();
char getScale ();
double getDegree ();
double convertFtoC (double);
double convertCtoF (double);
void getResults (double, double);

int main ()
{
programOverview ();
double degree = getDegree ();
char SCALE = getScale();
double Ftemp, Ctemp;

if (SCALE == 'F')
{
Ctemp = convertFtoC(degree);
Ftemp = degree;
}
else if (SCALE == 'C')
{
Ftemp = convertCtoF(degree);
Ctemp = degree;
}
else
{
cout << "ERROR: Invalid temperature scale" << endl;
exit (EXIT_FAILURE);
}

getResults(Ftemp, Ctemp);

return 0;
}

//This function displays a brief overview explaining the program to the user
void programOverview ()
{
cout << "This program will convert a temperature reading provided in" << endl;
cout << "either Fahrenheit or Celsius to the other measurement scale." << endl;
}

//This function requires the user to enter the temperature scale to be used
char getScale ()
{
char scale;
cout << "Enter the letter of the temperature scale that will be used:" << endl;
cout << "F = Fahrenheit; C = Celsius)" << endl;
cin >> scale;
return scale;
}

//This function requires the user to enter the temperature reading in degrees
double getDegree ()
{
double degree;
cout << "Enter your temperature reading in degrees:" << endl;
cin >> degree;
return degree;
}

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

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

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

It doesn't want to run at all. Please, help!
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
#include <iostream>
#include <iomanip>
using namespace std;

void programOverview ();
void callProg ();
void FtoC ();
void CtoF ();
void getResults (double, double);

int main ()
{
programOverview ();
callProg();

return 0;
}

//This function displays a brief overview explaining the program to the user
void programOverview ()
{
cout << "This program will convert a temperature reading provided in" << endl;
cout << "either Fahrenheit or Celsius to the other measurement scale." << endl;
}

//This function requires the user to enter the temperature scale to be used
void callProg()
{
int scale;
cout << "Enter the letter of the temperature scale that will be used:" << endl;
cout << "1) Fahrenheit   2) = Celsius)" << endl;
cin >> scale;

switch (scale)
{
	case 1 : FtoC();
	case 2 : CtoF();
	default : cout << "Nonvalid selection!" << endl;
}
}

//This function requires the user to enter the temperature reading in degrees
double getDegree ()
{
double degree;
cout << "Enter your temperature reading in degrees:" << endl;
cin >> degree;
return degree;
}

//This function converts a Fahrenheit temperature to Celsius
void FtoC ()
{
	
double Ctemp, Ftemp;
Ftemp = getDegree();
Ctemp = (Ftemp - 32) / 1.8;
getResults(Ftemp, Ctemp);

}

//This function converts a Celsius temperature to Fahrenheit
void CtoF ()
{
double Ftemp, Ctemp;
Ctemp = getDegree();
Ftemp = Ctemp*1.8 + 32;
getResults(Ftemp, Ctemp);

}

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


I would do something like this, brief up the functions, called a switch statement instead of asking for char. I would make the source even simpler though.

IHTH
Topic archived. No new replies allowed.