Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.46 KB | None | 0 0
  1. Easy Calculator with functions like Addition, Subtraction,
  2. Multiplication, division, percentage and even Power. The code is extremelysimple
  3. and very easy to understand.
  4.  
  5. #include<iostream.h>
  6. #include<conio.h>
  7. #include<math.h>
  8. void main()
  9. {
  10.     long double x,y;
  11.     char ch,ar;
  12.     do
  13.        {
  14.     clrscr();
  15.     cout<<"
  16.             *WELCOME TO CALCULATOR*
  17. ";
  18.     cout<<"
  19. This is a Calculator containing the following functions
  20.  
  21. Addition
  22. Subtraction
  23. Multiplication
  24. Division
  25. Percentage
  26.  
  27. Power
  28. ";
  29.     cout<<"
  30. Type
  31. [+] for Addition
  32. [-] for Subtraction
  33. [*] for
  34. Multiplication
  35. [/] for Division
  36. [%] for Percentage
  37. [^] for
  38. Power
  39. ";
  40.     cout<<"
  41. Enter Function To use =  ";
  42.     cin>>ch;
  43.     cout<<(char)7;
  44.     cout<<endl;
  45.     //For Addition
  46.        if(ch=='+')
  47.         {
  48.         clrscr();
  49.         cout<<"
  50. You are using Addition
  51. ";
  52.         cout<<"
  53. Enter First Number= ";
  54.         cin>>x;
  55.  
  56.         cout<<"
  57. Enter Second Number= ";
  58.         cin>>y;
  59.  
  60.         cout<<"
  61. Your answer is ";
  62.         cout<<x+y;
  63.         cout<<(char)7;
  64.         }
  65.     // For Subtraction
  66.      if(ch=='-')
  67.         {
  68.         clrscr();
  69.         cout<<"
  70. You are using Subtraction
  71. ";
  72.         cout<<"
  73. Enter First Number= ";
  74.         cin>>x;
  75.         cout<<"
  76. Enter Second Number= ";
  77.         cin>>y;
  78.         cout<<"
  79. Your answer is ";
  80.         cout<<x-y;
  81.         cout<<(char)7;
  82.         }
  83.     // For Multiplication
  84.      if(ch=='*')
  85.         {
  86.         clrscr();
  87.         cout<<"
  88. You are using Multiplication
  89. ";
  90.         cout<<"
  91. Enter First Number= ";
  92.         cin>>x;
  93.         cout<<"
  94. Enter Second Number= ";
  95.         cin>>y;
  96.         cout<<"
  97. Your answer is ";
  98.         cout<<x*y;
  99.         cout<<(char)7;
  100.         }
  101.     // For Division
  102.      if(ch=='/')
  103.         {
  104.         clrscr();
  105.         cout<<"
  106. You are using Division
  107. ";
  108.         cout<<"
  109. Enter First Number= ";
  110.         cin>>x;
  111.         cout<<"
  112. Enter Second Number= ";
  113.         cin>>y;
  114.         cout<<"
  115. Your answer is ";
  116.         cout<<x/y;
  117.         cout<<(char)7;
  118.         }
  119.         // For Percentage
  120.      if(ch=='%')
  121.         {
  122.         clrscr();
  123.         cout<<"
  124. You are using Percentage
  125. ";
  126.         cout<<"
  127. Enter Number= ";
  128.         cin>>x;
  129.         cout<<"
  130. Enter Percentage= ";
  131.         cin>>y;
  132.         cout<<"
  133. Your answer is ";
  134.         cout<<y/100*x;
  135.         cout<<(char)7;
  136.     }
  137.         //For Power
  138.     if(ch=='^')
  139.         {
  140.         clrscr();
  141.         cout<<"
  142. You are using Power
  143. ";
  144.         cout<<"
  145. Enter Number= ";
  146.         cin>>x;
  147.         cout<<"
  148. Enter Power= ";
  149.         cin>>y;
  150.         cout<<"
  151. Your answer is ";
  152.         cout<<pow(x,y);
  153.         cout<<(char)7;
  154.     }
  155.         cout<<endl;
  156.         cout<<"
  157. Do you want to continue..Y/N?";
  158.         cin>>ar;
  159.  
  160.         }
  161.         while(ar=='Y'|| ar=='y');
  162.         if(ar=='N' || ar=='n')
  163.         {
  164.             cout<<"
  165. Thankyou for using this Calculator.Good Bye.
  166. ";
  167.             cout<<"
  168. Press any key to exit.......";
  169.         }
  170.  
  171.         getch();
  172.         cout<<(char)7;
  173.  
  174. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement