Advertisement
Guest User

Untitled

a guest
Sep 26th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. void SumProductDifference(int, int, int&, int&, int&);
  7. int Power(int a, int b);
  8. bool GoAgain();
  9.  
  10. int main() {
  11. int a, b;
  12. int choice;
  13. int sum, product, difference;
  14. do
  15. {
  16. cout << "================================================" << endl;
  17. cout << "=====Welcome to AB Calculator 2016 Edition======" << endl;
  18. cout << "==== 1 - SumProductDifference Function ======" << endl;
  19. cout << "==== 2 - Power of Function ======" << endl;
  20. cout << "==== 3 - Quit ======" << endl;
  21. cout << "= Make A Selection: ======" << endl;
  22. cout << "================================================" << endl;
  23. cin >> choice;
  24.  
  25. switch (choice) {
  26. case '1': SumProductDifference(a, b, sum, product, difference);
  27. break;
  28. case '2': Power(a, b);
  29. break;
  30. case '3':
  31. break;
  32. default:
  33. break;
  34. }
  35.  
  36. return 0;
  37.  
  38. } while (choice != 3);
  39. return 0;
  40.  
  41. }
  42.  
  43. bool GoAgain() {
  44. char answer;
  45.  
  46. cout << "would you like to go again (y/n) ==> ";
  47. cin >> answer;
  48.  
  49. return answer == 'y';
  50. }
  51.  
  52. void SumProductDifference(int a, int b, int& s, int& p, int& d) {
  53.  
  54.  
  55. cout << "Enter two integers: ";
  56. cin >> a, b;
  57.  
  58. s = a + b;
  59. p = a * b;
  60. d = a - b;
  61.  
  62. cout << "The sum of " << a << " + " << b << " = " << s << endl;
  63. cout << "The product of " << a << " * " << b << " = " << p << endl;
  64. cout << "The difference of " << a << " - " << b << " = " << d << endl;
  65.  
  66.  
  67. }
  68.  
  69. int Power(int a, int b) {
  70. int total = 1;
  71. int i;
  72. cout << "Enter a number: ";
  73. cin >> a;
  74.  
  75. cout << "Raise this integer to the power of: ";
  76. cin >> b;
  77.  
  78. for ( i = 1; i < b; i++) {
  79. total = total *b;
  80. }
  81. return total;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement