Browse Source

Update 'converter.cpp'

Fixed some formatting, and playing with kelvin conversions
testing
ludwig 2 years ago
parent
commit
e93c300144
  1. 39
      converter.cpp

39
converter.cpp

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

Loading…
Cancel
Save