# Celcius Conversion Loop

• May 7th, 2013, 07:09 PM
bertonius
Celcius Conversion Loop
So everything seems to be working fine here, but after the first calculation that converts 0C to 32F, it just adds increments of 1 to each Fahrenheit. Why isn't the formula being repeated for each increasing value of Celcius? Help would be greatly appreciated, as I have spent hours trying to figure this out.:wave:

Code:

```# include <iostream> # include <iomanip> using namespace std; int main() {                 double c;         cout << setw(4) << "Celcius" << setw(7) << "" << "Fahrenheit" << endl;                         for (c = 0; c <= 20; c++)                 {                         double f = (9/5) * c + 32;                                                                                 cout << setw(4) << c << setw(7) << " " << " " << " " << " " << f << endl;         }                                                           return 0;         }```
• May 7th, 2013, 07:50 PM
Paul McKenzie
Re: Celcius Conversion Loop
Quote:

Originally Posted by bertonius
So everything seems to be working fine here, but after the first calculation that converts 0C to 32F, it just adds increments of 1 to each Fahrenheit. Why isn't the formula being repeated for each increasing value of Celcius? Help would be greatly appreciated, as I have spent hours trying to figure this out.:wave:

What do you think this gives you?
Code:

`(9/5)`
When you divide an integer by an integer, the result is an integer.

Regards,

Paul McKenzie
• May 7th, 2013, 08:41 PM
bertonius
Re: Celcius Conversion Loop
Thank you, Paul. I changed the formula to (1.8 * c) + 32 instead, and it is working. Here's what it looks like now:
Code:

```# include <iostream> # include <iomanip> using namespace std; int main() {                 int c;         cout << setw(4) << "Celcius" << setw(7) << "" << "Fahrenheit" << endl;                         for (c = 0; c <= 20; c++)                 {                         int f = (1.8 * c) + 32;                                                                                 cout << setw(4) << c << setw(7) << " " << " " << " " << " " << f << endl;         }                                                           return 0;         }```
• May 7th, 2013, 09:57 PM
Paul McKenzie
Re: Celcius Conversion Loop
Quote:

Originally Posted by bertonius
Thank you, Paul. I changed the formula to (1.8 * c) + 32 instead, and it is working.

You could have easily just done this:
Code:

`(9.0 / 5.0)`
The numerator and denominator are both floating-point (double), so the result will be a double instead of having the truncation done as in (9/5).

Regards,

Paul McKenzie