Write your question here.
I am new at C++ and having problems with this code, it always takes the first option on the IF even if I hardcode the option to a different number, any ideas?
int main()
{
void calcfar(int inputtemp); /* subroutine to calculate f degrees to c degrees */
void calccel(int inputtemp); /* subroutine to calculate c degrees to f degrees */
wchar_t selection='1';
int temperature;
printf( "Temperature conversion \n");
printf( "Please choose one of the following \n");
printf( "1 = Farhenheit to Celsius conversion \n");
printf( "2 = Celsius to Farhenheit conversion \n");
printf( "Enter any other key to exit: ");
scanf("%c", &selection);
printf( "Enter the temperature that you would like to convert: ");
scanf_s("%i", &temperature);
if (selection = '2')
calccel(temperature); /* call celsius conversion */
elseif(selection = '1')
calcfar(temperature); /* call farhenheit conversion */
else
printf("Exiting program\n");
return(0);
} /* end main */
void calcfar(int inputtemp)
{
int converttemp;
converttemp = (inputtemp -32) * (5.0/9.0);
printf("The Fahrenheit/Celsius conversion is %3f %06.3f\n", converttemp);
return;
} /* end function */
void calccel(float inputtemp)
{
float converttemp;
converttemp = (9.0/5.0) * (inputtemp + 32);
/* printf( "The Celsius/Fahrenheit conversion is %3f %6.3f\n", converttemp); */
printf("The Celsius conversion is %f\n", converttemp);
return;
} /* end function */
int main()
{
void calcfar(int inputtemp); /* subroutine to calculate f degrees to c degrees */
void calccel(int inputtemp); /* subroutine to calculate c degrees to f degrees */
wchar_t selection='1';
int temperature;
printf( "Temperature conversion \n");
printf( "Please choose one of the following \n");
printf( "1 = Farhenheit to Celsius conversion \n");
printf( "2 = Celsius to Farhenheit conversion \n");
printf( "Enter any other key to exit: ");
scanf("%c", &selection);
printf( "Enter the temperature that you would like to convert: ");
scanf_s("%i", &temperature);
if (selection == '2')
calccel(temperature); /* call celsius conversion */
elseif(selection == '1')
calcfar(temperature); /* call farhenheit conversion */
else
printf("Exiting program\n");
return(0);
} /* end main */
void calcfar(int inputtemp)
{
int converttemp;
converttemp = (inputtemp -32) * (5.0/9.0);
printf("The Fahrenheit/Celsius conversion is %3f %06.3f\n", converttemp);
return;
} /* end function */
void calccel(float inputtemp)
{
float converttemp;
converttemp = (9.0/5.0) * (inputtemp + 32);
/* printf( "The Celsius/Fahrenheit conversion is %3f %6.3f\n", converttemp); */
printf("The Celsius conversion is %f\n", converttemp);
return;
} /* end function */