Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- double fiveNinths = 0.5555555555555556;
- double FtoC(double f)
- {
- return (f - 32) * fiveNinths;
- }
- double FtoK(double f)
- {
- return (f - 32) * (fiveNinths)+273.15;
- }
- double CtoF(double c)
- {
- return c * 1.8 + 32;
- }
- double CtoK(double c)
- {
- return c + 273.15;
- }
- double KtoF(double k)
- {
- return (k - 273.15) * 1.8 + 32;
- }
- double KtoC(double k)
- {
- return k - 273.15;
- }
- int main()
- {
- double temp;
- short tempSelect;
- string f = "F", c = "C", k = "K";
- system("cls");
- cout << "Temperature Converter" << endl;
- cout << "1. Fahrenheit into Celsius/Kelvin" << endl;
- cout << "2. Celsius into Fahrenheit /Kelvin" << endl;
- cout << "3. Kelvin into Fahrenheit/Celsius" << endl;
- cout << "4. Exit." << endl;
- cin >> tempSelect;
- switch (tempSelect)
- {
- case 1:
- system("cls");
- cout << "Fahrenheit into Celsius/Kelvin Converter" << endl;
- cin >> temp;
- system("cls");
- cout << "Fahrenheit into Celsius/Kelvin Converter" << endl;
- cout << temp << "F = " << FtoC(temp) << c << endl;
- cout << temp << "F = " << FtoK(temp) << k << endl;
- system("pause");
- main();
- break;
- case 2:
- system("cls");
- cout << "Celsius into Fahrenheit /Kelvin Converter" << endl;
- cin >> temp;
- system("cls");
- cout << "Celsius into Fahrenheit /Kelvin Converter" << endl;
- cout << temp << "C = " << CtoF(temp) << f << endl;
- cout << temp << "C = " << CtoK(temp) << k << endl;
- system("pause");
- main();
- break;
- case 3:
- system("cls");
- cout << "Kelvin into Fahrenheit/Celsius Converter" << endl;
- cin >> temp;
- system("cls");
- cout << "Kelvin into Fahrenheit/Celsius Converter" << endl;
- cout << temp << "K = " << KtoF(temp) << f << endl;
- cout << temp << "K = " << KtoC(temp) << c << endl;
- system("pause");
- main();
- break;
- case 4:
- system("cls");
- cout << "Goodbye." << endl;
- return 0;
- break;
- default:
- main();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment