What to covert:
Celcius to Ferenhite
Ferenhite to Celcius
Enter your choice 1 or 2:
2
Enter the Ferenhite Value:
203.94
203.94 Degree Ferenhite =0 Degree Celcius
--------------------------------
Process exited after 23.17 seconds with return value 0
Press any key to continue . . .
What to covert:
Celcius to Ferenhite
Ferenhite to Celcius
Enter your choice 1 or 2:
1
Enter the Celcius Value:
203
203 Degree Celcius =235 Degree Ferenhite
--------------------------------
Process exited after 5.753 seconds with return value 0
Press any key to continue . . .
# include <iostream>
usingnamespace std;
class Tempurature
{
float c, f;
double con;
int choice;
public:
int TakeInput (void);
void Convert (int); // <--
void DisplayResult (void);
};
int Tempurature :: TakeInput (void)
{
cout
<< "What to covert:\n" << "Celcius to Ferenhite\n"
<< "Ferenhite to Celcius\n" << "Enter your choice 1 or 2:\n";
cin >> choice;
if (choice == 1)
{
cout << "Enter the Celcius Value:\n";
cin >> c;
}
else
{
cout << "Enter the Ferenhite Value:\n";
cin>> f;
}
return choice; // <--
}
void Tempurature :: Convert (int choice)
{
if (choice == 1)
{
con = c * 9/5. + 32; // <--
}
else
{
con = (f - 32.)* 5/9; // <--
}
}
void Tempurature :: DisplayResult (void)
{
if (choice == 1)
cout << c << " "<< "Degree Celcius =" << con << " " << "Degree Ferenhite\n";
else
cout << f << " " << " Degree Ferenhite =" << con << " " << "Degree Celcius\n";
}
int main ()
{
Tempurature dc;
int selection = dc.TakeInput(); // <--
dc.Convert(selection);
dc.DisplayResult();
return 0;
}
What to covert:
Celcius to Ferenhite
Ferenhite to Celcius
Enter your choice 1 or 2:
1
Enter the Celcius Value:
100
100 Degree Celcius =212 Degree Ferenhite
Program ended with exit code: 0
Messrs Daniel Fahrenheit and Anders Celsius would appreciate you spelling their names correctly too :)