# Won't Convert

This is a discussion on Won't Convert within the C++ Programming forums, part of the General Programming Boards category; This code will convert Celsius to Fahrenheit, but it will not convert Fahrenheit to Celsius can any one help me ...

1. ## Won't Convert

This code will convert Celsius to Fahrenheit, but it will not convert Fahrenheit to Celsius can any one help me its my first program really on my own. its a fairly simple Program but im 15yr old so gotta start somewhere

Code:
```#include <iostream>
using namespace std;
int main()
{
double far;
double cel;
int choice;
do{
cout <<"1. Celsius to Fahrenheit.\n"<<"2. Fahrenheit to Celsius\n"<<"3. Exit\n"<<"Your choice ( 1-3 ): ";
cin >>choice;
switch (choice){
case 1:
cout<<"Please Enter Degrees in Celsius: ";
cin>>cel;
far = ((9/5) * cel +32;
cout<<"Degrees in Fahrenheit is: "<<far<<"\n";
break;
case 2:
cout<<"Please Enter Degrees in Fahrenheit: ";
cin>>far;
cel = (5/9) * (far-32);
cout<<"Degrees in Celsius is: "<<cel<<"\n";
break;
case 3:
cout<<"Good bye\n";
exit;
break;
default:
cout<<"Please Enter a Valid choice 1-3. Thank You.";
break;
}
}while(choice !=3);
system("Pause");
}```

2. On both of your conversions, use floats (floating point values) instead of integers:

cel = (5/9)....

is 0 in integer division. Use 5.0/9.0 and vice versa for the other conversion.

Todd

3. When i made the variables into floats instead of doubles it said something about failure to convert double to float possible loss of data but it works fine with doubles thank you

4. Yes you are correct. Floats and doubles are both floating point. I wasn't paying attention to your current set of types.

You're welcome.

Todd

5. Reading this makes me feel all sentimental. A temperature converter was my very first C program and the teacher decided not to tell us about integers. So of course I made the same mistake.

Now that I think about it, I think I started swearing about the same time I started programming.

6. Originally Posted by baitman18
When i made the variables into floats instead of doubles it said something about failure to convert double to float possible loss of data but it works fine with doubles thank you
That's because things like 9.0/5.0 will be computed as a value of type double, and conversion of that back to type float implies a reduction of precision. If you want things to work with float variables, make these 9.0f/5.0f.