-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTemperatureConversion.cpp
More file actions
34 lines (27 loc) · 1.02 KB
/
TemperatureConversion.cpp
File metadata and controls
34 lines (27 loc) · 1.02 KB
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
#include <iostream>
int main(){
double temp;
char unit;
std::cout << "************** TEMPERATURE CONVERSION *************" << '\n';
std::cout << "F = Fahrenheit\n";
std::cout << "C = Celsius\n";
std::cout << "What unit would you like to convert to? (F or C): ";
std::cin >> unit;
if(unit == 'F' || unit == 'f'){
std::cout << "Enter the temperature in Celsius: ";
std::cin >> temp;
temp = (1.8 * temp) +32.0; // convert Celsius to Fahrenheit
std::cout << "The temperature in Fahrenheit is: " << temp << "F\n";
}
else if(unit == 'C' || unit == 'c'){
std::cout << "Enter the temperature in Fahrenheit: ";
std::cin >> temp;
temp = (temp - 32) / 1.8; // convert Fahrenheit to Celsius
std::cout << "The temperature in Celsius is: " << temp << "C\n";
}
else{
std::cout << "Invalid unit! Please enter either F or C.\n";
}
std::cout << "***************************************************" << '\n';
return 0;
}