strlength

Simple calculator in c

May 4th, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.77 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #define RED     "\x1b[31m"
  5. #define GREEN   "\x1b[32m"
  6. #define RESET   "\x1b[0m"
  7.  
  8. int main(int argc, char const *argv[])
  9. {
  10.     int hax;
  11.     float results, addition1, addition2, times1, times2, sub1, sub2, div1, div2;
  12.  
  13.     printf(RED "1. Addition\n2. Subtraction\n3. Multiplication\n4. Division\n" RESET "\n");
  14.     printf("Enter Choice: ");
  15.     scanf("%d", &hax);
  16.  
  17.      if (hax == 1)
  18.      {
  19.         printf("You Have Entered Addition!\n\n");
  20.         printf("Enter Number set 1 > ");
  21.         scanf("%f", &addition1);
  22.         printf("Enter Number set 2 > ");
  23.         scanf("%f", &addition2);
  24.  
  25.         results = addition1 + addition2;
  26.         printf(GREEN "%.2f + %.2f = %.2f\n", addition1, addition2, results);
  27.  
  28.      }
  29.      else if (hax == 2)
  30.      {
  31.         printf("You Have Entered Subtraction!\n\n");
  32.         printf("Enter Number set 1 > ");
  33.         scanf("%f", &sub1);
  34.         printf("Enter Number set 2 > ");
  35.         scanf("%f", &sub2);
  36.  
  37.         results = sub1 - sub2;
  38.         printf(GREEN "%.2f - %.2f = %.2f\n", sub1, sub2, results);
  39.      }
  40.  
  41.      else if (hax == 3)
  42.      {
  43.         printf("You Have Entered Multiplication!\n\n");
  44.         printf("Enter Number set 1 > ");
  45.         scanf("%f", &times1);
  46.         printf("Enter Number set 2 > ");
  47.         scanf("%f", &times2);
  48.  
  49.         results = times1 * times2;
  50.         printf(GREEN "%.2f - %.2f = %.2f\n", times1, times2, results);
  51.  
  52.      }
  53.      else if (hax == 4)
  54.      {
  55.         printf("You Have Entered Division!\n\n");
  56.         printf("Enter Number set 1 > ");
  57.         scanf("%f", &div1);
  58.         printf("Enter Number set 2 > ");
  59.         scanf("%f", &div2);
  60.  
  61.         results = div1 / div2;
  62.         printf(GREEN "%.2f - %.2f = %.2f\n", div1, div2, results);
  63.      }
  64.      else{
  65.         printf("Error!\n");
  66.      }
  67.     return 0;
  68. }
Add Comment
Please, Sign In to add comment