Skip to content

Instantly share code, notes, and snippets.

@met4000
Created November 24, 2016 02:33
Show Gist options
  • Save met4000/59f6912426be6c0ac542c1d81d06b17e to your computer and use it in GitHub Desktop.
Save met4000/59f6912426be6c0ac542c1d81d06b17e to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
int main()
{
string from, to, disp, v;
int value;
bool a = true;
do {
cout << "What would you like to convert from?" << endl << ">>";
cin >> from;
} while (from != "C" && from != "F" && from != "K");
cout << "What would you like to convert to?" << endl << ">>";
cin >> to;
cout << "Calculator:" << endl << ">>";
disp = to == "C" ? "Celsius" : to == "F" ? "Fahrenheit" : to == "K" ? "Kelvin" : "N/A";
while (a) {
cin >> v;
if (from == "F") {
value = (value - 32) / 1.8;
}
else if (from == "K") {
value -= 273;
}
if (to == "F") {
value = value * 1.8 + 32;
}
else if (to == "K") {
value += 273;
}
cout << value << " degrees " << disp << endl << ">>";
}
a = true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment