Why the function getchar () is skipped, and does not run in the above program in C
Code:
/*I tried to make a simple program, that calculate:
*1) how much money will cost us a product if we have percentage decrease for it;
*2) how much money we can save after buying a reduced/decreased product versus its real price; */
/*I want to implement some of the two cases in switch statement, but the program does not allow me to do that, because the getchar () function is skipped*/
#include <stdio.h>
int main (void)
{
float real_price, percentage;
char ch;
printf ("Enter the real price of the product: ");
scanf ("%f", &real_price);
printf ("\nEnter the percentage decrease: ");
scanf ("%f", &percentage);
printf ("\nPress 1 if you want to calculate the PRICE OF THE PRODUCT AFTER THE REDUCING\nPress 2 if you want to calculate THE REDUCED PRICE OF THE PRODUCT: ");
ch = getchar (); //this statement is not implemented
switch (ch) {
case '1':
printf ("The price of the product after the reducing is: %f ", real_price - (percentage / 100) * real_price);
case '2':
printf ("The reduced price of the product is: %f", (percentage/100)*real_price);
break;
default:
printf ("getchar () is not implemented\n"); //respectively this statement is implemented
}
return 0;
}