|
|
|
#include <iostream>
|
|
|
|
#include <iomanip>
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Menu(){ // <- The menu is (mostly) static, no need for it to be in main
|
|
|
|
cout << "Simple temperature converter \n";
|
|
|
|
cout << "Conversion options \n [1]C to F \n [2]F to C \n [3]F to K \n [4]C to K \n [5]Quit" << endl;
|
|
|
|
cout << "Select option [1-5]: ";
|
|
|
|
}
|
|
|
|
|
|
|
|
double C, F, K;
|
|
|
|
|
|
|
|
double convertC2K(double C, double K) {
|
|
|
|
K = (C + 273.15);
|
|
|
|
return(K);
|
|
|
|
}
|
|
|
|
|
|
|
|
double convertC(double C, double F) { // <- converts to Celsius
|
|
|
|
C = (F - 32) / 1.8;
|
|
|
|
return(C);
|
|
|
|
}
|
|
|
|
|
|
|
|
double convertF(double C, double F) { // <- converts to fahrenheit
|
|
|
|
F = (C * 1.8) + 32;
|
|
|
|
return(F);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
int input;
|
|
|
|
Menu();
|
|
|
|
cin >> input;
|
|
|
|
|
|
|
|
while (input != 4) {
|
|
|
|
|
|
|
|
if (input == 1) {
|
|
|
|
cout << "Enter temperature in Celsius: ";
|
|
|
|
cin >> input;
|
|
|
|
C = input;
|
|
|
|
cout << setprecision(2) << convertF(C, F) << endl;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (input == 2) {
|
|
|
|
cout << "Enter temperature in Fahrenheit: ";
|
|
|
|
cin >> input;
|
|
|
|
F = input;
|
|
|
|
cout << setprecision(2) << convertC(C, F) << endl;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (input == 4) {
|
|
|
|
cout << "Enter temperature in Celsius: ";
|
|
|
|
cin >> input;
|
|
|
|
C = input;
|
|
|
|
cout << setprecision(2) << convertC2K << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cout << "\nExiting...";
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Created by fuze on 8/13/22.
|
|
|
|
//
|