Advertisement
tonygms3

IF_ELSE_Simple_calculator

Oct 24th, 2017
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.66 KB | None | 0 0
  1. //by Nicholas Tony Gomes
  2. #include <stdio.h>
  3. int main()
  4. {
  5.     double a,b;
  6.     char chr;
  7.     int counter;
  8.  
  9.  
  10.     printf("Enter two numbers\n");
  11.     scanf("%lf%lf",&a,&b);
  12.  
  13.     printf("Enter if you want to add subtract or multiply or divide\n");
  14.  
  15.     scanf(" %c",&chr);
  16.  
  17.     if(chr=='a'||chr=='A')
  18.     {
  19.         printf("%.2lf",a+b);
  20.  
  21.     }
  22.     else if(chr=='s'||chr=='S')
  23.     {
  24.         printf("%.2lf",a-b);
  25.     }
  26.     else if(chr=='m'||chr=='M')
  27.     {
  28.         printf("%.2lf",a*b);
  29.     }
  30.     else if(chr=='d'||chr=='D')
  31.     {
  32.         printf("%.2lf",a/b);
  33.     }
  34.     else
  35.     {
  36.         printf("invalid input");
  37.     }
  38.  
  39.  
  40.  
  41.  
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement