dazedandconfused dazedandconfused - 2 months ago 18
C Question

How to debug an error "'X' was not declared in this scope" in C?

/* 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


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

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.