Advertisement
Eather

Calculator

Jun 16th, 2011
433
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.98 KB | None | 0 0
  1.                        /*Bismillahir Rahmanur Rahim*/
  2. //Template created by topcoder00
  3.  
  4. # include <stdio.h>
  5. # include <math.h>
  6. using namespace std;
  7.  
  8. int choice;
  9. void start()
  10. {
  11. printf ("Instruction to use calculator\n");
  12. printf ("Press 0 for Addition\n");
  13. printf ("Press 1 for Subtraction\n");
  14. printf ("Press 2 for Multipication\n");
  15. printf ("Press 3 for Division\n");
  16. printf ("Press 4 for Modulus\n");
  17. printf ("Press 5 for Power\n");
  18. printf ("Press 6 for Factrolial\n");
  19. printf ("Press 7 for And Oparation\n");
  20. printf ("Press 8 for Or Oparation\n");
  21. printf ("Press 9 for Xor Oparation\n");
  22. printf ("Press -1 for Exit\n");
  23. }
  24.  
  25. void add()
  26. {
  27.     double a,b;printf("Give two numbers with space.\n");
  28.     scanf("%lf %lf",&a,&b);
  29.     printf("%.2lf",a+b);
  30. }
  31. void sub()
  32. {
  33.     double a,b;printf("Give two numbers with space.\n");
  34.     scanf("%lf %lf",&a,&b);
  35.     printf("%.2lf",a-b);
  36. }
  37. void mul()
  38. {
  39.     double a,b;printf("Give two numbers with space.\n");
  40.     scanf("%lf %lf",&a,&b);
  41.     printf("%.2lf",a*b);
  42. }
  43. void div()
  44. {
  45.     double a,b;printf("Give two numbers with space.\n");
  46.     again:
  47.     scanf("%lf %lf",&a,&b);
  48.     if(b==0){printf("2nd number cann't be 0. Please re-enter two numbers.\n");goto again;}
  49.     printf("%.2lf",a/b);
  50. }
  51. void mod()
  52. {
  53.     int a,b;printf("Give two numbers with space.\n");
  54.     again:
  55.     scanf("%d %d",&a,&b);
  56.     if(b==0){printf("2nd number cann't be 0. Please re-enter two numbers.\n");goto again;}
  57.  
  58.     printf("%d",a % b);
  59. }
  60. void power()
  61. {
  62.     double a,b;printf("Give two numbers with space.\n");
  63.     scanf("%lf %lf",&a,&b);
  64.     printf("%.2lf",pow(a,b));
  65. }
  66. void fact()
  67. {
  68.     int a;printf("Give the number.\n");
  69.     scanf("%d",&a);
  70.     int m=1;
  71.     for(int i=1;i<=a;i++)
  72.     {
  73.         m*=i;
  74.     }
  75.     printf("%d",m);
  76. }
  77. void andop()
  78. {
  79.     int a,b;printf("Give two numbers with space.\n");
  80.     scanf("%d %d",&a,&b);
  81.     printf("%d",a & b);
  82. }
  83. void orop()
  84. {
  85.     int a,b;printf("Give two numbers with space.\n");
  86.     scanf("%d %d",&a,&b);
  87.     printf("%d",a | b);
  88. }
  89. void xorop()
  90. {
  91.     int a,b;printf("Give two numbers with space.\n");
  92.     scanf("%d %d",&a,&b);
  93.     printf("%d",a ^ b);
  94. }
  95.  
  96. int main()
  97. {
  98.     start();
  99.     printf("Choose an option\n");
  100.     again:
  101.     scanf("%d",&choice);
  102.  
  103.     switch(choice)
  104.     {
  105.         case 0:
  106.         add();break;
  107.         case 1:
  108.         sub();break;
  109.         case 2:
  110.         mul();break;
  111.         case 3:
  112.         div();break;
  113.         case 4:
  114.         mod();break;
  115.         case 5:
  116.         power();break;
  117.         case 6:
  118.         fact();break;
  119.         case 7:
  120.         andop();break;
  121.         case 8:
  122.         orop();break;
  123.         case 9:
  124.         xorop();break;
  125.         case (-1):
  126.         return 0;
  127.         default:
  128.         printf("Wrong entry. Please give your choice\n");
  129.         goto again;
  130.     }
  131.     printf("\n\nAgain choice an option\n\n");
  132.     goto again;
  133.     cout<<"\n\n\n\n\n\n\nDesigned by Iftekhar ahmed eather,\nStudent of CSE (07 batch),\nBUBT, Mirpur";
  134.     return 0;
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement