Advertisement
mahatma_xande

ex10lista05

Aug 28th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.90 KB | None | 0 0
  1. /*
  2. It is a simple calculator able to operate over just two numbers.
  3. */
  4.  
  5. #include <stdio.h>
  6.  
  7. int main(){
  8.     float a, b;
  9.     char op;
  10.  
  11.     do{
  12.         printf("\nEnter a, b: ");
  13.         scanf("%f %f", &a, &b);
  14.  
  15.         printf("\nChoose among the operation (+, -, *, /,) or hit E to exit: ");
  16.         scanf("%c", &op);
  17.         op = getchar();
  18.  
  19.         if(op == '+')
  20.             printf("\nResult = %.2f\n", a + b);
  21.             else if(op == '-')
  22.                 printf("\nResult = %.2f\n", a - b);
  23.                 else if(op == '*')
  24.                     printf("\nResult = %.2f\n", a * b);
  25.                     else if(op == '/')
  26.                         printf("\nResult = %.2f\n", a / b);
  27.                         else if(op == 'E')
  28.                             printf("\nEnd!\n");
  29.                             else
  30.                                 printf("\nInvalid!\n");
  31.     } while(op != 'E');
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement