Hello All,
This is just a simple programming challenging from a book I'm using to learn C, it doesn't call for the if/else statement but I wanted to add it. I have used if/else before successfully, but for some reason now on the else portion it wont do the calculation. At first I thought celsius was a reserved word and thats why it was failing, but so I changed the variables name but still same error.
Code:
#include <stdio.h>
int
main(void)
{
int Choice; /* stores users choice on conversion */
double fahrenheit; /* stores the temp in Fahrenheit */
double centigrade; /* stores the temp in Celsius */
/* Asks the user what they want to convert. */
printf("Please choose how you want to convert\n");
printf("Press 1 for Celsius to Fahrenheit\n");
printf("Press 2 for Fahrenheit to Celsius: ");
scanf("%d", &Choice);
/*Determines what the user chooses */
if (Choice == 1)
{
/* Obtains the temp and converts to fahrenheit */
printf("\nPlease enter in the Temp in degree's Celsius: ");
scanf("%lf", ¢igrade);
fahrenheit = (9/5 * centigrade)+32;
printf("\n %.2f Celsius is %.2f Fahrenheit\n ", centigrade, fahrenheit);
}
else
{
/* Obtains the temp and converts to Celsius */
printf("\nPlease enter in the Temp in degree's Fahrenheit: ");
scanf("%lf", &fahrenheit);
centigrade = (5/9)(fahrenheit - 32);
printf("\n %.2f Fahrenheit is %.2f Celsius\n", fahrenheit, centigrade);
}
return(0);
}
when compiled I get this error ConvertTemp.c:40: error: called object is not a function and line 40 is centigrade = (5/9)(fahrenheit -32); but the equation in the if statement runs fine, and if I take else out completely it runs fine. I read around about people with similar errors, and tried to use the fixes they had but most were when they were actually calling a function aside from stdio.h I'm not calling any others. Thanks in advance.