infinite loop

• 03-31-2011
leahknowles
infinite loop
This program works fine , right up to when i enter 0E for example to end tests it doesnt do anything its not ending nor printing out the printf statement

Code:

``` #include <stdio.h> int main (void)   {   float value1;  float accumulator = 0;   char operator;    printf ("\t\tCalulator\n");  printf ("\t\t---------\n");  do { printf("Type in your test\n");  scanf("%f %c", &value1, &operator);        switch (operator)   {       case 'S':       accumulator = value1;   printf("%.2f\n", value1);     break;         case 's':       accumulator = value1;     printf("%.2f\n", value1);       break;         case '+':       accumulator += value1;       printf("%.2f\n", accumulator);       break;        case '-':       accumulator = accumulator - value1;       printf("%.2f\n", accumulator);       break;        case '/':      accumulator = accumulator / value1;      printf("%.2f\n", accumulator);        break;       case '*':       accumulator = accumulator * value1;      printf("%.2f\n", accumulator);                break;         case 'E':         printf("End of Tests\n");       break;         case 'e':       printf("End of Tests\n");        break;             default:      printf("UNKNOWN OPERATOR\n");       break;   } } while (operator != 'e' && operator != 'E');   printf("\n%.2f\n", accumulator); return 0; }```
• 03-31-2011
stahta01
Hint: 'e' never equals 'E'.

Edit: I guess my Boolean logic needs some work. Go with bithub answer first.

Tim S.
• 03-31-2011
bithub
Quote:

Originally Posted by stahta01
Hint: 'e' never equals 'E'.

Tim S.

That's a horrible hint since it has nothing to do with his problem.

```if(scanf("%f %c", &value1, &operator) != 2) {     printf("Invalid input\n");     return 0; }```