Advertisement
Guest User

H1

a guest
Nov 24th, 2014
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.28 KB | None | 0 0
  1. /* Alexander Shmakov (Alex)
  2. * CIS 22A Fall 2014
  3. * Laboratory Assignment H
  4. * Problem H2
  5. *
  6. * This program takes two inputs
  7. * and finds the sum of the inputs.
  8. * It does this twice.
  9. **/
  10.  
  11. #include <iostream>
  12.  
  13. using namespace std;
  14.  
  15. int sum(int a, int b);
  16. void takeInput(int& a, int& b);
  17.  
  18. int main()
  19. {
  20.     int x, y;
  21.  
  22.     takeInput(x, y);
  23.     cout << x << " + " << y << " = " << sum(x,y) << endl;
  24.     takeInput(x, y);
  25.     cout << x << " + " << y << " = " << sum(x, y) << endl;
  26.  
  27.     return 0;
  28. }
  29.  
  30. //************************************
  31. // Method:    sum
  32. // Returns:   int
  33. // int a:
  34. // int b:
  35. // Description:
  36. //************************************
  37. int sum(int a, int b)
  38. {
  39.     return a + b;
  40. }
  41.  
  42. //************************************
  43. // Method:    takeInput
  44. // Returns:   void
  45. // int & a:   first input
  46. // int & b:   second input
  47. // Description: Prompts the user to input two integers and saves them
  48. //************************************
  49. void takeInput(int& a, int& b)
  50. {
  51.     cout << "Please enter the first number: ";
  52.     cin >> a;
  53.     cout << "Please enter the second number: ";
  54.     cin >> b;
  55. }
  56.  
  57. /* Execution Results:
  58.  
  59.  Please enter the first number: 3
  60.  Please enter the second number: 4
  61.  3 + 4 = 7
  62.  Please enter the first number: 5
  63.  Please enter the second number: 49
  64.  5 + 49 = 54
  65.  
  66.  **/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement