-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTempConvert.cpp
73 lines (54 loc) · 1.32 KB
/
TempConvert.cpp
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
#include <iostream>
using namespace std;
void CtoF();
void FtoC();
void getChoice() {
string input;
bool complete = false;
do {
cout << " Press F to convert Fahrenheit to Celsius \n Press C to convert Celsius to Fahrenheit \n or Press Q to quit. \n";
cin >> input;
if(input == "F" || input == "f") {
FtoC();
// Fahrenheit to Celsius
complete = true;
}
else if(input == "C" || input == "c") {
CtoF();
// Celsius to Fahrenheit
complete = true;
}
else if(input == "Q" || input == "q") {
cout << "Goodbye \n";
// exit
exit(0);
}
else {
cout << "Invalid input, select something from the menu. \n" << endl;
}
} while(complete == false);
}
int main() {
getChoice();
// the getChoice() function get selection and then either starts the temperature converting functions or exits the program
return 0;
}
void CtoF() {
double tempc;
double tempf;
// Ask the user
cout << "Enter the temperature in Celsius " << endl << "> ";
cin >> tempc;
// Calculate
tempf = (tempc / 5) * 9 + 32;
// Output
cout << "The temperature is " << tempf << " degrees Farenhiet. \n";
}
void FtoC() {
double tempf;
double tempc;
cout << "Enter the temperature in Farenhiet " << endl << "> ";
cin >> tempf;
tempc = (tempf - 32) / 1.8;
cout << "The temperature is " << tempc << " degrees Celsius.\n";
}