below is my calculator programming.I want to make it show "maths error" when any number divided by 0, but i get any number +,-,*,/ by 0 also get maths error.I need u guys to correct my program,please.
Code:#include <stdio.h> int main() { float num1, num2; char operation; while (1) { scanf("%f%c%f", &num1, &operation, &num2); if (operation == '+') printf("%f\n", num1+num2); if (operation == '-') printf("%f\n", num1-num2); if(operation == '*') printf("%f\n", num1*num2); if (num2 == 0) { printf ("maths error\n"); } else if (operation == '/') printf("%f\n", num1/num2); } return 0; }



LinkBack URL
About LinkBacks



