here's some overkill, but it might give you something to ponder...
Code:
#include <iostream>
using std::cout;
using std::endl;
using std::cin;
class Temp
{
public:
void setT(float t){ temperature = t; }
float getC(){ return ( (5.0/9.0) * (temperature - 32.0) ); }
float getF(){ return ( (9.0/5.0) * temperature + 32.0 ); }
private:
float temperature;
};
int main()
{
Temp t;
char choice;
float c, f;
do
{
cout << "\nEnter [1] to convert C to F, [2] to convert F to C," << endl
<< "or [3] to quit: ";
do
{
cin >> choice;
}while((choice != '1') && (choice != '2') && (choice != '3'));
if(choice == '1')
{
cout << "\nEnter degrees in C: ";
cin >> c;
t.setT(c);
cout << c << "C = " << t.getF() << "F" << endl;
}
if(choice == '2')
{
cout << "\nEnter degrees in F: ";
cin >> f;
t.setT(f);
cout << f << "F = " << t.getC() << "C" << endl;
}
}while(choice != '3');
cin.ignore();
cout << "\nPress [Enter] to continue...";
cin.ignore(256, '\n');
return 0;
}