I'm trying to create a simple calculator that keeps prompting the user for input until the user enters the standard input ("number" "operator") and the operator = 'E'.
I know in java I'd just use a while(true) loop (as I did in here), but I get the error "true undeclared." I'm new to C and am not sure what I'm doing wrong.. thanks for any help!
Here is my code:
Code:#include <stdio.h> #include <stdlib.h> main() { double num; double accum; char op; printf("Initialize your Accumulator with data of the form 'number' 'S' which sets the Accumulator \ to the value of your number\n"); scanf("%f %c", &num, &op); while (1) { if (op == 'S') { accum = num; } else if (op == '+') { accum = accum+num; } else if (op == '*') { accum = accum*num; } else if (op == '/') { accum = accum/num; } else if (op == '-') { accum = accum-num; } else if ((num == 0) && (op == '/')) { printf("Can not divide by 0.\n"); } else if (op == '-') { accum = accum-num; } else if ((num == 0) && (op == '/')) { printf("Can not divide by 0.\n"); } else if (op == 'E') { printf("Value in the Accumulator = %d \n", accum); printf("End of Calculations.\n"); exit(EXIT_SUCCESS); /*exits program if user enters E*/ } else { printf("Unknown operator.\n"); } printf("Value in the Accumulator = %f \n", accum); scanf("%f %c", &num, &op); }



LinkBack URL
About LinkBacks
.. thanks for any help! 




