Hello,

Do you know what is wrong with this?
Code:
/* print fahr-celc table for fahr = 0, 10, 20, ..., 100 */

int main (void)
{
int celc, fahr;
int lower, upper, step;

lower = 0;        /* lower limit of temperature scale */
upper = 100;    /* upper limit */
step = 10;        /* step size */

fahr = lower;
while (fahr <= uppur);
{
celc = 5*(fahr-32)/9;
printf("%d\t%d\n", fahr, celc);
fahr = fahr + step;
}
}
When I press execute, pelles c says:
Building main.obj.
D:\Documenten\Mijn_documenten\c programma's van mij\derde project\main.c(37): error #2048: Undeclared identifier 'uppur'.
*** Error code: 1 ***
Done.

I don't know what is wrong with this.

2. Check your spelling. Where do you define a variable with the name uppur?

Jim

Code:
int lower, upper, step;

// ...

while (fahr <= uppur);
When you fix this and see that the program appears to do nothing, think about whether or not you really want that semi-colon at the end of your "while()".

4. Also the following will probably not produce your desired results:
Code:
celc = 5*(fahr-32)/9;
You are using integer math, there are no fractions in integer math. So something like 1/2 will yield zero, with the fractional part discarded.

Jim

5. Originally Posted by jimblumberg
Also the following will probably not produce your desired results:
Code:
celc = 5*(fahr-32)/9;
You are using integer math, there are no fractions in integer math. So something like 1/2 will yield zero, with the fractional part discarded.

Jim
The other issue is that C uses BODMAS. So divisions happen before multiplications, and the expression becomes 5*((fahr-32)/9). fahr is rounded down to the lowest multiple of 5. If you write (5*(fahr-32))/9 instead, you will get what is probably an acceptably accurate integer result.

6. Originally Posted by Malcolm McLean
The other issue is that C uses BODMAS. So divisions happen before multiplications
No, C has precedence rules akin to BODMAS, but not quite the same. In particular, the / and * operators have the same precedence. Furthermore, precedence determines grouping, not necessarily the order of evaluation.

Originally Posted by Malcolm McLean
the expression becomes 5*((fahr-32)/9).
No, the grammar is such that * and / are left associative. Hence the expression 5*(fahr-32)/9 is equivalent to (5*(fahr-32))/9 rather than 5*((fahr-32)/9).