This program is supposed to prompt the user to either convert form celsius to degree or vice versa. Then ask for a temperature to be entered and ouput the result. When I enter the temperature, the conversion result always comes out to 0. It does this with both celsius to fahrenheit and fahrenheit to celsius. I cant seem to find the problem!
Code:
/*exercise 3.1 converting temperatures*/
#include <stdio.h>
#include <ctype.h>
int main()
{
char type = 0;
double degree = 0.0;
double result = 0.0;
printf("\nEnter A to convert celsius to fahrenheit or B to convert fahrenheit to celsius: ");
scanf("%c", &type);
printf("\nEnter degree: ");
scanf("%d", °ree);
switch (toupper(type))
{
case'A':
result = degree*1.8+32;
printf("\n%d degrees celsius is %d degrees fahrenheit", degree, result);
break;
case'B':
result = ((32 - degree)*5)/9;
printf("\n%d degrees fahrenheit is %d degrees celsius", degree, result);
break;
default:
printf("\nYou did not enter A or B, try again");
break;
}
}