Advertisement
vencinachev

Calculator-week3

Feb 28th, 2022
874
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.73 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main(){
  4.     double num1, num2;
  5.     char op;
  6.     while (scanf("%lf %c %lf", &num1, &op, &num2) != EOF){
  7.         /*if (op == '+'){
  8.             printf("%.2lf\n", num1 + num2);
  9.         } else if (op == '-'){
  10.             printf("%.2lf\n", num1 - num2);
  11.         } else {
  12.             fprintf(stderr, "Invalid operation!\n");
  13.         }*/
  14.         switch (op){
  15.             case '+':
  16.                 printf("%.2lf\n", num1 + num2);
  17.                 break;
  18.             case '-':
  19.                 printf("%.2lf\n", num1 - num2);
  20.                 break;
  21.             // *-> x , / zeroo
  22.             default:
  23.                 fprintf(stderr, "Invalid operation!\n");
  24.                 break;
  25.         }
  26.     }
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement