Last active
November 12, 2016 15:11
-
-
Save met4000/f55a90afd4922aff04d7294af365e43b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream>using namespace std; | |
inline bool isInteger(const std::string & s){ if(s.empty() || ((!isdigit(s[0])) && (s[0] != '-') && (s[0] != '+'))) return false ; | |
char * p ; strtol(s.c_str(), &p, 10) ; | |
return (*p == 0) ;} | |
int main() { string from, to, disp, v; int value; bool a = true; cout << "What would you like to convert from?" << endl << ">>"; cin >> from; 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 (!isInteger(v)) { a = false; } else { value << (int)v.front();//ERRORS 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