-2
//Converts Farenheit tempretaure to into the celsius scale

#include <stdio.h>
#define FREEZING_PT 32.0f
#define FACTOR 5.0f/9.0f

int main(void)
{
    float faren,c;

    printf("Enter the Farenheit temperature: ");
    scanf("%f",&faren);
    float c = (faren - FREEZING_PT)*FACTOR;

    printf("The required celsius tempreature is: %.1f\n", c);

    return 0;
}

Im a Complete C beginner and this may be very elementary but I cannot figure out the problem here.

In the above code, the value I get returned is always the Celsius temperature in integer values, even if it is a float type. For example, if the Fahrenheit temperature was 0°, the result in Celsius should be -17.7°, but I get the result only as -17°.

Edited code:

//Converts Farenheit tempretaure to into the celsius scale

#include <stdio.h>
#define FREEZING_PT 32.0f
#define FACTOR 5.0f/9.0f

int main(void)
{
    float faren,c;

    printf("Enter the Farenheit temperature: ");
    scanf("%f",&faren);
    c = (faren - FREEZING_PT)*FACTOR;

    printf("The required celsius tempreature is: %.1f\n", c);

    return 0;
}
MrKhonsu
  • 19
  • 4

1 Answers1

0

In your code, you've declared the variable 'c' twice. After removing the first declaration of the variable 'c', it's working properly.

I'm getting the correct output.

Enter the Farenheit temperature: 0

The required celsius tempreature is: -17.8

Enter the Farenheit temperature: 1

The required celsius tempreature is: -17.2

Enter the Farenheit temperature: 2

The required celsius tempreature is: -16.7

Remove the first declaration of the variable 'c'. It should work.

Md. Faisal Habib
  • 1,014
  • 1
  • 6
  • 14