fork download
  1. //Cameron Pham CS1A Chapter 9, p. 538, #5
  2. //
  3. /******************************************************************************
  4. * DROP LOWEST SCORE
  5. * ______________________________________________________________________________
  6. * This program accepts an integer value and modifies their values. The function
  7. * multiplies each original value by 10, exchanges their positions, and returns
  8. * the sum of the modified values.
  9. *
  10. * INPUT
  11. * Integers // The integer values inputted
  12. *
  13. * OUTPUT
  14. * X // New value of first integer
  15. * Y // New value of second integer
  16. * Sum // Sum of modified values
  17. *******************************************************************************/
  18. #include <iostream>
  19. using namespace std;
  20.  
  21. // Function prototype
  22. int doSomething(int* x, int* y);
  23.  
  24. int main()
  25. {
  26. int num1, num2;
  27. int result;
  28. // Get two integers from the user
  29. cout << "Enter the first integer: ";
  30. cin >> num1;
  31. cout << "Enter the second integer: ";
  32. cin >> num2;
  33. // Call the function using the addresses of the variables
  34. result = doSomething(&num1, &num2);
  35. // Display the modified values and returned result
  36. cout << "\nFirst integer: " << num1 << endl;
  37. cout << "Second integer: " << num2 << endl;
  38. cout << "Returned value: " << result << endl;
  39. return 0;
  40. }
  41. // Multiply and exchange the values using pointers
  42. int doSomething(int* x, int* y)
  43. {
  44. int temp = *x;
  45. *x = *y * 10;
  46. *y = temp * 10;
  47. return *x + *y;
  48. }
Success #stdin #stdout 0s 544KB
stdin
80 50
stdout
Enter the first integer: Enter the second integer: 
First integer: 500
Second integer: 800
Returned value: 1300