Original Post
I'm trying to simplify this bloated code for a function based Fahrenheit | Celsius conversion. #include <iostream> #include <cmath> using namespace std; double fTemp = 0.0f; double cTemp = 0.0f; int select = 0; double celsius_to_fahrenheit(double, double); double fahrenheit_to_celsius(double, double); const static float fiveNineths = 5.0F/9.0F; const static float nineFifths = 9.0F/5.0F; float fahrenheit_to_celsius( const float fTemp ) { return (fiveNineths * (fTemp - 32.0F)); } float celsius_to_fahrenheit( const float cTemp ) { return ( (nineFifths * cTemp) + 32.0F); } int main() { while (select ==0) { cout << "Please select from the following: \n"; cout << "Fahrenheit-to-Celsius [1], Celsius-to-Fahrenheit [2], Quit 3 \n"; cin >> select; if (select == 1) { cout << "Enter temperature in degree F to convert: "; cin >> fTemp; //passing the fTemp to the function cout << "The temperature in F, "<< fTemp <<" is " << fahrenheit_to_celsius(fTemp) <<" C\n\n"; } else if (select == 2) { cout <<"Enter temperature in degree C to convert: "; cin >> cTemp; //passing the CIN >> cTemp to the other function then calling it cout << "The temperature in C, "<< cTemp <<" is " << celsius_to_fahrenheit(cTemp) <<" F\n\n"; } else if (select == 3) exit(0); else cout << "Incorrect choice. Try again. \n\n"; select = 0; } system("PAUSE"); return EXIT_SUCCESS; }