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?
When you divide an integer by an integer, the result is an integer.
Regards,
Paul McKenzie
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;
}
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:
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