daily pastebin goal
84%
SHARE
TWEET

Untitled

a guest Sep 23rd, 2018 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. /* Lets define our functions */
  4. int add(int a, int b);
  5. int sub(int a, int b);
  6. int mult(int a, int b);
  7. int divide(int a, int b);
  8. int remain(int a, int b);
  9. void ask2run();
  10. /* ************************* */
  11.  
  12. int main()
  13. {
  14.     /* MENU */
  15.  
  16.     printf("==================================== \n");
  17.     printf("|********** CALCULATOR ************| \n");
  18.     printf("\n");
  19.     printf("|   BY.....Aditya Patange....      | \n");
  20.     printf("\n");
  21.     printf("|**********************************| \n");
  22.     printf("|        (1) Addition              | \n");
  23.     printf("|        (2) Subtraction           | \n");
  24.     printf("|        (3) Multiplication        | \n");
  25.     printf("|        (4) Division              | \n");
  26.     printf("|**********************************| \n");
  27.     printf("\n\n");
  28.     printf("** Enter your option ** \n");
  29.     int i;
  30.     scanf("%d", &i);
  31.  
  32.     /* END MENU */
  33.  
  34.     if (i == 1) //Addition
  35.     {
  36.         printf("\n\n");
  37.         printf(" ** ADDITION ** \n");
  38.         int add1;
  39.         int add2;
  40.         printf("Enter the first number: \n");
  41.         scanf("%d", &add1);
  42.         printf("Enter the second number: \n");
  43.         scanf("%d", &add2);
  44.         int sum;
  45.         sum = add(add1,add2);
  46.         printf("%d + %d = %d\n",add1,add2,sum);
  47.         ask2run();
  48.         return 0;
  49.     }
  50.  
  51.     if (i == 2) //Subtraction
  52.     {
  53.         printf("\n\n");
  54.         printf(" ** SUBTRACTION ** \n");
  55.         int sub1;
  56.         int sub2;
  57.         int diff;
  58.         printf("Enter the first number:\n");
  59.         scanf("%d", &sub1);
  60.         printf("Enter the number to subtract from first number:\n");
  61.         scanf("%d", &sub2);
  62.         diff = sub(sub1,sub2);
  63.         printf("%d - %d = %d\n", sub1, sub2, diff);
  64.         ask2run();
  65.         return 0;
  66.     }
  67.  
  68.     if (i == 3) //Multiplication
  69.     {
  70.         printf("\n\n");
  71.         printf(" ** MULTIPLICATION ** \n");
  72.         int multi1;
  73.         int multi2;
  74.         int prod;
  75.         printf("Enter the first number \n");
  76.         scanf("%d", &multi1);
  77.         printf("Enter the second number \n");
  78.         scanf("%d", &multi2);
  79.         prod = mult(multi1,multi2);
  80.         printf("%d * %d = %d\n", multi1, multi2, prod);
  81.         ask2run();
  82.         return 0;
  83.     }
  84.  
  85.     if (i == 4) //Division
  86.     {
  87.         printf("\n\n");
  88.         printf(" ** DIVISION ** \n");
  89.         int dividend;
  90.         int divisor;
  91.         int quotient;
  92.         int remainder;
  93.         printf("Enter your dividend \n");
  94.         scanf("%d", &dividend);
  95.         printf("Enter your divisor \n");
  96.         scanf("%d", &divisor);
  97.         quotient = divide(dividend,divisor);
  98.         remainder = remain(dividend,divisor);
  99.         printf("Your quotient is %d \n", quotient);
  100.         printf("Your remainder is %d \n", remainder);
  101.         ask2run();
  102.         return 0;
  103.  
  104.     }
  105.  
  106. return 0;
  107. }
  108.  
  109.  
  110.  
  111.  
  112. /* Functions */
  113.  
  114. int add(int a, int b)
  115. {
  116.     int sum;
  117.     sum = a + b;
  118.     return(sum);
  119. }
  120.  
  121. int sub(int a, int b)
  122. {
  123.     int sub;
  124.     sub = a - b;
  125.     return(sub);
  126. }
  127.  
  128. int mult(int a, int b)
  129. {
  130.     int prod;
  131.     prod = a * b;
  132.     return(prod);
  133. }
  134.  
  135. int divide(int a, int b)
  136. {
  137.     int quo;
  138.     quo = a / b;
  139.     return (quo);
  140. }
  141.  
  142. int remain(int a, int b)
  143. {
  144.     int rem;
  145.     rem = a % b;
  146.     return(rem);
  147. }
  148.  
  149. void ask2run() //Whether the user wants to run it again..
  150.                //Loop back to main()
  151. {
  152.     printf("\n\n");
  153.     printf("Would you like to run the program again ? \n");
  154.     printf("Press Y for yes and N for no.");
  155.     fflush(stdin);
  156.     char choice;
  157.     scanf("%c", &choice);
  158.  
  159.     if (choice == 'Y' || choice == 'y')
  160.     {
  161.          printf("\n\n\n\n\n\n\n\n\n\n\n");
  162.          main();
  163.     }
  164.     if (choice == 'N' || choice == 'n')
  165.     {
  166.     /* Do nothing bitch, just quit because abort() is just too mainstream */
  167.     }
  168.     else
  169.     {
  170.         printf("\n\n\n\n\n\n\n\n\n\n\n");
  171.         main();
  172.     }
  173. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top