ghin
ghin

Reputation: 1

Expected expression error on a temperature conversion table

Getting an "expected expression error" on line 17 when following the C programming book. Complete noob here and not sure what I'm doing wrong.

int main()
{
float fahr, celsius;
int lower, upper, step;

lower = 0; /* lower limit of temperature table */
upper = 300; /* upper limit */
step = 20; /*step size */

fahr = lower;
while (fahr <= upper ) {
    celsius = (5.0/9.0) * (fahr - 32.0);
    printf(“%3.0f %6.1f\n”, fahr, celsius);
    fahr = fahr + step;
    }
    return 0;
}

Upvotes: 0

Views: 85

Answers (2)

Pierre Fourgeaud
Pierre Fourgeaud

Reputation: 14510

printf(“%3.0f %6.1f\n”, fahr, celsius);
//     ^             ^   Those quotes are not standard

Replace those quotes by the standard ones :

printf("%3.0f %6.1f\n", fahr, celsius);
//     ^             ^

The compilers are strict, the “” and "" do not mean the same thing.

Upvotes: 2

simonc
simonc

Reputation: 42165

You need to replace the quotes “” in

printf(“%3.0f %6.1f\n”, fahr, celsius);

with standard double quotes ""

printf("%3.0f %6.1f\n", fahr, celsius);

As an aside, you should also #include <stdio.h> at the top of the file for a declaration of printf

Upvotes: 4

Related Questions