do while loop problem
Code:
#include <stdio.h> 2) However, at first when you enter as choice 1,2 or 3 and then enter unmeaning values (like * - / + . , etc.) it is starting to loop forever. Although at first isn't a thing like this, Why is it happening at second? |
Forget scanf, use fgets and sscanf. Don't ignore the return values.
|
First lap the entered data matches d so is sucessfully matched to choice. Second lap the scanf matches no data. This time %d doesn't effect choice, but the previous value is still available to switch statement
Try choice=0; before scanf or more precisely catch the value returned by scanf and act accordingly. In this case anything other than 1 implies some sort of error. |
All times are GMT -5. The time now is 12:31 AM. |