I have never programmed before, and am starting with some C using tutorials such as howstuffworks.com
In this particular tutorial: HowStuffWorks "How C Programming Works"
A list of Fahrenheit to Celsius conversions are made every 10 degrees F, adding in a line at 98.6 F, then continuing.
I do not understand the given code (the final piece of code on that page) on the loop that adds the 98.6 F line with no bugs.
Code:
#include <stdio.h>
int main()
{
float a, b;
a = 0;
b = -1;
while (a <= 100)
{
if ((a > 98.6) && (b < 98.6))
{
printf("%6.2f degrees F = %6.2f degrees C\n",
98.6, (98.6 - 32.0) * 5.0 / 9.0);
}
printf("%6.2f degrees F = %6.2f degrees C\n",
a, (a - 32.0) * 5.0 / 9.0);
b = a;
a = a + 10;
}
return 0;
}
If b starts at -1, then is attached to a at the end of the loop, and a goes up by 10 each loop, then there is never a point at which a > 98.6 and b< 98.6.
On the end of the 10th loop, a is 90 and goes up by 10 to 100. But starting at -1, b should be going up to 99, which is higher than 98.6. So why does that meet the requirement of a > 98.6 and b< 98.6
I feel that I am misunderstanding the point of b being in the code, because it doesnt seem to matter what b is assigned to in the beginning, as long as it is assigned to a at the end. Where am I going wrong in my thinking?
Thank you so much for your time. I will get better.