I am writing a Fahrenheit to Celsius converter that also converts Celsius to Fahrenheit using a switch break feature in C++. The program is where the user enters in a number followed by a "c" for Celsius or an "f" for Fahrenheit, then they hit enter and the program will calculate the conversion and display the temperature converted. The Fahrenheit to Celsius conversion works and is accurate, however the Celsius to Fahrenheit calculation always converts to 1.66607e+62 no matter what number of fahrenheit you enter. Also it doesnt calculate on the first time you enter in the temperature, you have to enter it in twice before it works and converts it. I am just wondering what do I have to do to fix these problems thanks. Heres my code :
#include <iostream> //cout
#include <conio.h> //getch
using namespace std;
int main()
{
double celsius, fahrenheit, temp;
char unit;
cout << "Enter the temperature you wish to convert followed by F for Fahrenheit or C for Celsius: " << endl;
cin >> temp;
cin >> unit;
cin >> fahrenheit;
cin >> celsius;
switch (unit)
{
case 'F': temp = fahrenheit;
celsius = (5.0 / 9.0) * (fahrenheit - 32.0);
cout << celsius << " degrees celsius";
break;
case 'f': temp = fahrenheit;
celsius = (5.0 / 9.0) * (fahrenheit - 32.0);
cout << celsius << " degrees celsius";
break;
case 'C': temp = celsius;
fahrenheit = (9.0 / 5.0) * celsius + 32.0;
cout << fahrenheit << " degrees fahrenheit";
break;
case 'c': temp = celsius;
fahrenheit = (9.0 / 5.0) * celsius + 32.0;
cout << fahrenheit << " degrees fahrenheit";
break;
default: cout << "Invalid Format";
break;
}
_getch();
return 0;
}