Converts Celsius to Fahrenheit or vice versa. Simple really
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.0 KiB

2 years ago
#include <iostream>
using namespace std;
2 years ago
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]Quit" << endl;
cout << "Select option [1-3]: ";
}
2 years ago
double C, F;
2 years ago
double convertC(double C, double F){ // <- converts to Celsius
2 years ago
C = (F - 32) / 1.8;
return(C);
}
2 years ago
double convertF(double C, double F){ // <- converts to fahrenheit
2 years ago
F = (C * 1.8) + 32;
return(F);
}
2 years ago
int main() {
2 years ago
int input;
Menu();
2 years ago
cin >> input;
2 years ago
if (input == 3) {
2 years ago
cout << "Quitting..." << endl;
}
2 years ago
else if (input == 1){
cout << "Enter temperature in Celsius: ";
cin >> input;
C = input;
cout << convertF( C, F) << endl;
}
else if (input == 2){
2 years ago
cout << "Enter temperature in Fahrenheit: ";
2 years ago
cin >> input;
F = input;
cout << convertC(C, F);
}
2 years ago
return(0);
}
2 years ago
2 years ago
//
// Created by fuze on 8/13/22.
//