Okay, so I'm finally getting back into programming after a loooooong hiatus. I'm starting off with the book 'The C Programming Language' by Brian Kernighan and Dennis Ritchie.
Believe it or not I'm stuck on the first chapter, not because of format or the concept of programming (I've taken java classes and done very well), but because of a formula to convert temperatures from Fahrenheit to Celsius and back.
The first exercise has me write a program to print a table converting fahrenheit to celsius. The while loop looks like this:
So far so good, the formula works and the conversion is correct.
The next exercise wants me to reverse the table and do a celsius to fahrenheit conversion. My while loop looks like this:
At this point I'm not worried about the formatting, so don't worry about the printf statement, I can't get the formula to work. I verified the formula from here, but it doesn't do the conversion correctly. This table says that 0 Celsius is 57.6 Fahrenheit. I can get it to work correctly if I use
but I'm confused why the one above doesn't work.
I'm sure I've missed something simple, does anyone have any ideas?
Thanks!
Patrick
Believe it or not I'm stuck on the first chapter, not because of format or the concept of programming (I've taken java classes and done very well), but because of a formula to convert temperatures from Fahrenheit to Celsius and back.
The first exercise has me write a program to print a table converting fahrenheit to celsius. The while loop looks like this:
Code:
while (fahr <= upper) {
celsius = (5.0/9.0) * (fahr-32.0);
printf("%3.0f\t%6.1f\n", fahr, celsius);
fahr = fahr + step;
}
The next exercise wants me to reverse the table and do a celsius to fahrenheit conversion. My while loop looks like this:
Code:
while (celsius <= upper) {
fahr = (9.0/5.0) * (celsius+32.0);
printf("%6.1f\t%3.0f\n", celsius, fahr);
celsius = celsius + step;
}
Code:
fahr = (celsius*1.8)+(32.0);
I'm sure I've missed something simple, does anyone have any ideas?
Thanks!
Patrick