While loop

I am trying to write my first while loop. It's supposed to start with a Celsius temperature of 100, then calculate the Fahrenheit equivalent, then subtract one from the C temp until the Fahrenheit and Celsius are equal (which is at -40).

I have absolutely no idea where I'm going wrong. I've spent all day on the internet trying to figure it out. I'm sure it's just a dumb mistake. Help, please?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
using namespace std; 
 
int main() 
{

	cout.setf(ios::fixed);
	cout.setf(ios::showpoint);
	cout.precision(2);

	int cels;        // degrees celsius
	int fahr;        // degrees fahrenheit

	cout << "This program determines which temperature\n"; 
	cout << "is the same in both Celsius and Fahrenheit.\n";
		
		cels = 100;
		//fahr = (9/5) * cels + 32;
		
		while (cels != fahr)
		{

			fahr = (9/5) * cels + 32;
			cels = cels - 1;
			
		}
		
		cout << "The temperature " << fahr << " is the same in both Fahrenheit and Celsius.\n";
		cout << "Goodbye.\n";
		
		
return (0);

} 


(Also, sorry if the formatting is wrong!! Any help is greatly appreciated.)
Formatting is fine, actually, except that one return at the end but that's forgivable compared to other things I've seen.
Now then, what is going wrong? I would warn you now that, if you divide 9 by 5, you get 1 because those are both integers. If you divide 9.0 by 5 or 9 by 5.0 you get 1.8.
You should also decrease cels before evaluating fahr
Okay, I switched the cels/fahr thing and made it 9.0/5.0, so now the code is:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>
using namespace std; 
 
int main() 
{

	cout.setf(ios::fixed);
	cout.setf(ios::showpoint);
	cout.precision(2);

	int cels;        // degrees celsius
	int fahr;        // degrees fahrenheit

	cout << "This program determines which temperature\n"; 
	cout << "is the same in both Celsius and Fahrenheit.\n";
		
		cels = 100;
		fahr = (9.0/5.0) * cels + 32;
		
		while (cels != fahr)
		{
		
			cels = cels - 1;
			fahr = (9/5) * cels + 32;
			
		}
		
		cout << "The temperature " << fahr << " is the same in both Fahrenheit and Celsius.\n";
		cout << "Goodbye.\n";
		
		
return (0);

} 


But the output just ends up being "This program determines which temperature is the same in both Celsius and Fahrenheit." Is there some reason that cels never equals fahr exactly? Why does the program keep getting stuck in the loop?

Thanks again!
On line 24 you still have integer division
Oh my gosh, that worked. Thank you thank you thank you, Bazzy!!!
Topic archived. No new replies allowed.