# Why aren't my answers having decimal places

• 03-13-2010
curls8
Why aren't my answers having decimal places
Hi all,

I am doing the Temperture Converter problem on this site: Temperature Converter Programming Challenge - Cprogramming.com

I basically did a quick program and used the example numbers giving on the above site (10 for low, 20 high, 4 for the step). I am getting the "right answers" but they are intergers and have no decimal places but 2 of the answers should have decimal places. I declared the varibles with double and tried with float but I am getting the same answer. When I input (10.2 for low, 20 for high, 4 for step) all the answers come out with a .2 at the end so I know it can print decimal places.

Am I missing something here? like do I have to declare how many decimal places somewhere?

Here is my program below.

Code:

```#include <cstdlib> #include <iostream> using namespace std; void Celsius_to_Fahrenheit(double celsius_low, double celsius_high, int step); int main() {     double low_limit, high_limit;     int increments;     char exit;         cout<<"Enter low Celcius  ";     cin>>low_limit;     cout<<"\nEnter high Celcius  ";     cin>>high_limit;     cout<<"\nEnter the ingrements you would like it to calculate by  ";     cin>>increments;             cout<<"\n\nCelsius          Fahrenheit\n";     cout<<"_______          __________\n";         Celsius_to_Fahrenheit(low_limit, high_limit, increments);         cout<<"Press any key then enter to exit";     cin>>exit;     return 0; } void Celsius_to_Fahrenheit(double celsius_low, double celsius_high, int step) {         double Fahrenheit;       while(celsius_high >= celsius_low)        {           Fahrenheit = 9/5 * (celsius_low + 32);                     cout<<celsius_low<<"                "<<Fahrenheit<<"\n";                     celsius_low = celsius_low + step;                                               }         }```
• 03-13-2010
_Mike
Code:

`Fahrenheit = 9/5 * (celsius_low + 32);`
Your problem is the red part in this line..
You'd think 9/5 would be 1.8, but because you are using integers the decimal part gets thrown away and the line above becomes equal to
Code:

`Fahrenheit = 1 * (celsius_low + 32);`
You could use 9.0/5.0 instead, or just 1.8

Edit:
Btw, you are using the wrong formula for the conversion ;)
Remove the ( ) and with the above fix it should give you the correct answers.
• 03-13-2010
curls8
Thanks!!! It worked!!
• 03-14-2010
Maulrus
This is a bit off-topic, but I had the exact same problem while trying to complete the same exercise.
• 03-15-2010
UltraKing227
definitely off-topic.