#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <math.h>
int main()
{
float minutes;
float degrees;
float feet;
float fahrenheit;
int choice;
//display menu options
do{
printf("Please choose one of the following options:\n");
printf("\n\t\t1.Minutes to Hours");
printf("\n\t\t2.Degrees to Radians");
printf("\n\t\t3.Feet to Meters");
printf("\n\t\t4.Degrees Fahrenheit to degrees Celsius");
printf("\n\t\t5.Exit\n\t\t");
fflush(stdin);
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("\nPlease enter the number of minutes: ");
scanf("%f",&minutes);
printf("\nThe equivlent number of hours is: %.1f hr/s\n", minutes/60);
break;
case 2:
printf("\nPlease enter a number in degrees: ");
scanf("%f",°rees);
printf("\nThe equivalent number of radians is: %f°\n",degrees*M_PI/180);
break;
case 3:
printf("\nPlease enter a number in feet: ");
scanf("%f",&feet);
printf("\nThe equivalent number of meters is: %f\n",feet/3.2808);
break;
case 4:
printf("\nPlease enter a number in degrees fahrenheit: ");
scanf("%f",&fahrenheit);
printf("\nThe equivalent number of degrees celsius is %.2f degrees\n",(fahrenheit-32)*5/9);
break;
case 5:
printf("\n\t\tGoodbye\n");
break;
default:
printf("\nThis option does not exist\n");
break;
}
}while(choice!=5);
system("pause");
}
the problem is that scanf("%f", ...); leaves the end of line in the stream. The next iteration getchar(); reads the end of line and the switch goes to the default