Loop fails to include error msg. Also, program crashes when non number entered
How can I fix this so it can include the error msg. Also, the loop fails to include the error msg when an option other than 1 or 2 is entered.
PHP Code:
#include <stdio.h>
int main(void)
{
float original_temp, new_temp;
int option;
printf("Enter the value you wish to convert.\n");
scanf("%f", &original_temp);
do{
printf("You entered %.5f. \n", original_temp);
printf("Now, what is the unit of measurment of the value you just entered please type 1 or 2:\n"
"1. Fahrenheit\n"
"2. Celsius\n");
scanf("%d", &option);
} while(option!=1 && option!=2);
if(option==1)
{
printf("You have %.5f degrees Fahrenheit.\n",original_temp );
new_temp = (((original_temp - 32) / 9) * 5);
printf("When converted to degrees Celsius you get %.5f degrees Celsius\n", new_temp);
}
else if(option==2)
{
printf("You have %.5f degrees Celsius.\n", original_temp);
new_temp = (((original_temp / 5) * 9) + 32);
printf("When converted to degrees Fahrenheit you get %.5f degrees Fahrenheit\n", new_temp);
}
else
{
printf("Error\n");
}
return 0;
}