Advertisement
18126

HW1 - ex2

Feb 24th, 2022
952
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.71 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int main(int args, char *argv[]) {
  6.     double num1;
  7.     char ch;
  8.     double num2;
  9.     double sum;
  10.     if(args > 1) {
  11.         printf("ERROR\n");
  12.         return 2;
  13.     }
  14.     while( scanf("%lf %c %lf", &num1, &ch, &num2) != EOF) {
  15.         if(ch == '+') {
  16.             sum = num1 + num2;
  17.         } else if(ch == '-') {
  18.             sum = num1 - num2;
  19.         } else if(ch == 'x') {
  20.             sum = num1 * num2;
  21.         } else if(ch == '/') {
  22.             sum = num1 / num2;
  23.         } else {
  24.             printf("There is no function: '%c' in this calculator!\n", ch);
  25.             return 2;
  26.         }
  27.         printf("Product = %.2lf\n", sum);
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement