Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void getData(int& num1, int& num2);
  5. void doTheMath(int num1, int num2, int& sum, int& difference, int& product, int& quotient, int& remainder);
  6. void displayResults(int num1, int num2, int& sum, int& difference, int& product, int& quotient, int& remainder);
  7.  
  8. int main()
  9. {
  10. int num1;
  11. int num2;
  12. int sum;
  13. int difference;
  14. int product;
  15. int quotient;
  16. int remainder;
  17.  
  18. getData(num1, num2);
  19. doTheMath(num1, num2, sum, difference, product,quotient,remainder);
  20. displayResults(num1, num2, sum, difference, product, quotient, remainder);
  21. return 0;
  22. }
  23.  
  24. void getData(int& num1, int& num2)
  25. {
  26. cout << "Enter two intergers: ";
  27. cin >> num1;
  28. cin >> num2;
  29. }
  30.  
  31. void doTheMath(int num1, int num2, int& sum, int& difference, int& product, int& quotient, int& remainder)
  32. {
  33. sum = num1 + num2;
  34. difference = num1 - num2;
  35. product = num1 * num2;
  36.  
  37. if (num2 != 0) {
  38. remainder = num1 % num2;
  39. quotient = num1 / num2;
  40. }
  41. }
  42.  
  43. void displayResults(int num1, int num2, int& sum, int& difference, int& product, int& quotient, int& remainder)
  44. {
  45.  
  46. if (num2 == 0)
  47. {
  48. cout << "Here are the results:\n\nThe sum of " << num1 << " and " << num2 << " is " << sum;
  49. cout << "\nThe difference, (" << num1 << " minus " << num2 << ") is " << difference;
  50. cout << "\nThe product of " << num1 << " and " << num2 << " is " << product;
  51. cout << "\nCannot divide by zero\n\n";
  52. }
  53. if (num2 != 0)
  54. {
  55. cout << "Here are the results:\n\nThe sum of " << num1 << " and " << num2 << " is " << sum;
  56. cout << "\nThe difference, (" << num1 << " minus " << num2 << ") is " << difference;
  57. cout << "\nThe product of " << num1 << " and " << num2 << " is " << product;
  58. cout << endl << num1 << " divided by " << num2 << " is " << quotient << " with a remainder of " << remainder << "\n\n";
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement