Question from book:
Write a program that does temperature conversion from Fahrenheit to Celsius, your program should :
- prompt the user for which type of conversion they want to do.
- prompt the user for the temperature they want to convert.
I am getting incorrect output.I'm not sure where i'm going wrong.I'm new to c language. Any help is greatly appreciated. Here is my code:
#include <stdio.h>
#include <stdlib.h>
int main()
{int f, c, f_or_c;
printf("Would you like to convert Fahrenheit (1) or Celsius (2)?\n");
scanf("%d", &f_or_c);
if(f_or_c==1)
{
printf("Enter the temperature in Fahrenheit to convert?\n");
scanf("%d", &c);
f = 1.8*c + 32.0;
printf("Celsius of %d is %d degrees.\n");
}
if(f_or_c==2)
{
printf("Enter the temperature in Celsius to convert?\n");
scanf("%d", &f);
c = (f-32)*5/9;
printf("Fahrenheit of %d is %d degrees.\n");
}
return 0;
}