Advertisement
CoatlessEskimo

A Very Bad Calculator

Apr 23rd, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.13 KB | None | 0 0
  1. // The original version of this code was created by Kenneth Davis (@Coatless_Eskimo).
  2. // If you modify this code, include this message and release the source code for free.
  3.  
  4. #include <iostream>
  5.  
  6. int additionLoop()
  7. {
  8.     int x{};
  9.     int y{};
  10.     std::cout << "Please define X. \n";
  11.     std::cin >> x;
  12.     std::cout << "Please define Y. \n";
  13.     std::cin >> y;
  14.     std::cout << "Your answer is: " << x + y << "." << std::endl;
  15. }
  16.  
  17. int subtractionLoop()
  18. {
  19.     int x{};
  20.     int y{};
  21.     std::cout << "Please define X. \n";
  22.     std::cin >> x;
  23.     std::cout << "Please define Y. \n";
  24.     std::cin >> y;
  25.     std::cout << "Your answer is: " << x - y << "." << std::endl;
  26. }
  27.  
  28. int multiplicationLoop()
  29. {
  30.     int x{};
  31.     int y{};
  32.     std::cout << "Please define X. \n";
  33.     std::cin >> x;
  34.     std::cout << "Please define Y. \n";
  35.     std::cin >> y;
  36.     std::cout << "Your answer is: " << x * y << "." << std::endl;
  37. }
  38.  
  39. int divisionLoop()
  40. {
  41.     int x{};
  42.     int y{};
  43.     std::cout << "Please define X. \n";
  44.     std::cin>>x;
  45.     std::cout << "Please define Y. \n";
  46.     std::cin>>y;
  47.     std::cout << "Your answer is: " << x / y << "." << std::endl;
  48. }
  49.  
  50. int squaringLoop()
  51. {
  52.     int x{};
  53.     std::cout << "Please define X. \n";
  54.     std::cin >> x;
  55.     std::cout << "Your answer is: "<< x * x << "." << std::endl;
  56. }
  57.  
  58. int helpMePlease()
  59. {
  60.     std::cout << "This code made and compiled by Coatless Eskimo. \n";
  61. }
  62.  
  63. int calculatorLoop()
  64. {
  65.     std::cout << "Please choose an operation to be performed. \n" << "  \n" << "1. Addition \n" << "2. Subtraction \n" << "3. Multiplication \n" << "4. Division \n" << "5. Square \n" << "6. Help" << std::endl;
  66.     int choice{};
  67.     std::cin >> choice;
  68.     if (choice == 1)
  69.         additionLoop();
  70.     else if (choice == 2)
  71.         subtractionLoop();
  72.     else if (choice == 3)
  73.         multiplicationLoop();
  74.     else if (choice == 4)
  75.         divisionLoop();
  76.     else if (choice == 5)
  77.         squaringLoop();
  78.     else if (choice == 6)
  79.         helpMePlease();
  80.     else
  81.         std::cout << "Please make a valid selection. \n";
  82.     calculatorLoop();
  83. }
  84.  
  85. int main()
  86. {
  87.     calculatorLoop();
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement