When i enter any number except 1 and 2, nothing happens and i have no choice except force exiting using ctrl + c.Code:#include <iostream> //#include <string> using namespace std; class temp { private: float t,r; char choice; public: void readtemp () { cout << "1. Celsius to Fahreinheit" << endl << "2. Fahreinheit to Celsius" << endl; cout << "Enter your choice : "; do { cin >> choice; }while (choice != '1' && choice != '2'); cout << endl << "Enter the temperature : "; cin >> t; } void changetemp () { if (choice == 1) r = ((9/5.0) * t) + 32; else r = ((t-32) * 5) / 9; } void showtemp () { if (choice == 1) cout << t << char (248) << " Celsius = " << r << char (248) << " Fahreinheit"; else cout << t << char (248) << " Fahreinheit = " << r << char (248) << " Celsius"; } }; int main () { temp t1; t1.readtemp (); t1.changetemp (); t1.showtemp (); return 0; }
Compiler : Codeblocks 8.02