fork download
  1. //@Author Damien Bell
  2. #include <iostream>
  3. #include <cmath>
  4. using namespace std;
  5. int main(){
  6. int choice=0;
  7. double x, y, z=0;
  8.  
  9. while (choice != -9){
  10. cout << "\nWelcome to calculator, Press 1 to add" <<endl << "Press 2 to subtract" << endl << "Press 3 to multiply" <<endl;
  11. cout << "Press 4 to divide." << endl << "Press 5 to find the modulo. " <<endl<< "Press 6 to raise to a power"<<endl <<"Press -9 to quit" <<endl;
  12. cout <<"Make your choice: ";
  13. cin >> choice;
  14.  
  15. if (choice == -9){
  16. break;
  17. }
  18. cout << "\nEnter number 1: ";
  19. cin >> x;
  20.  
  21. cout << "\nEnter number 2: ";
  22. cin >> y;
  23.  
  24.  
  25. if (choice ==1){
  26. z= x+y;
  27. cout << x << " +" << y << " =" <<z <<endl;
  28. }
  29. if (choice ==2){
  30. z= x-y;
  31. cout << x << " -" << y << " =" <<z <<endl;
  32. }
  33. if (choice ==3){
  34. z= x*y;
  35. cout << x << " *" << y << " =" <<z <<endl;
  36. }
  37. if (choice ==4){
  38. z= x/y;
  39. cout << x << " /" << y << " =" <<z <<endl;
  40. }
  41. if (choice ==5){
  42. z= (int (x))%(int (y));
  43. cout << x << " %" << y << " =" <<z <<endl;
  44. }
  45. if (choice ==6){
  46. z= pow(x,y);
  47. cout << x << " ^" << y << " =" <<z <<endl;
  48. }
  49.  
  50. }
  51. return 0;
  52. }
  53.  
  54.  
  55. /*
  56.  Make a calculator that runs in a while loop, that we have the option of getting out of
  57.  *
  58.  Add, subtract, divide, multiply, and raise to a power.
  59.  *
  60.  *
  61.  */
Success #stdin #stdout 0s 2864KB
stdin
6
5
3
-9
stdout
Welcome to calculator, Press 1 to add
Press 2 to subtract
Press 3 to multiply
Press 4 to divide.
Press 5 to find the modulo. 
Press 6 to raise to a power
Press -9 to quit
Make your choice: 
Enter number 1: 
Enter number 2: 5 ^3 =125

Welcome to calculator, Press 1 to add
Press 2 to subtract
Press 3 to multiply
Press 4 to divide.
Press 5 to find the modulo. 
Press 6 to raise to a power
Press -9 to quit
Make your choice: