dazedandconfused dazedandconfused - 3 months ago 11
C Question

In C, please help me understand these errors for program regarding Fahrenheit to kelvin

/* Converting Fahrenheit to Kelvin */

#include <stdio.h>

int
main (void)

{

int fahr,
double kelvin;

printf ("Enter input \n");
scanf("%d", &fahr);
kelvin = 5/9 (fahr-32) + 273.15);
printf ("you get %f. \n", kelvin)

return (0);
}


The errors I get are:
line 13 column 1: expected unqualified-id before 'double'
17 6 : 'kelvin' was not declared in this scope
17 27 : [Error] expression cannot be used as a function
28 : recipe for target 'Project1edit.o' failed

please note I am using Dev-C++ to write this code. This is my first program in C ever.

Answer

I did a correction in your code.

Try this:

#include <stdio.h>

int main (void)
{
        float fahr;
        double kelvin;

        printf ("Enter input \n");
        scanf("%f", &fahr);

        kelvin = (5.0 / 9.0 * (fahr - 32) + 273.15);
        printf("you get %.2f\n", kelvin);
}

Also, You missed the multiplication operator, * and brace (.

kelvin = (5/9 *(fahr-32) + 273.15);

Also, solved syntax error in your code.