//Amari Mosley CSC5 Chapter 9, P. 538 #5
/********************************************************************
*
* REWRITE POINTER
* _________________________________________________________________
*
* This program rewrites a function that originally uses reference
* variables so that it uses pointers instead. The function swaps
* the values of two integers after multiplying each by 10 and
* returns the sum of the modified values.
*
* _________________________________________________________________
*
* INPUT
* x : First integer entered by the user
* y : Second integer entered by the user
* OUTPUT
* result : Sum of the modified integer values
*
********************************************************************/
#include <iostream>
using namespace std;
// Function Prototype
int doSomething(int*, int*);
int main()
{
// INPUT
int x;
int y;
// Get values from the user
cout << "Enter the first integer: ";
cin >> x;
cout << "Enter the second integer: ";
cin >> y;
// Call the function using pointers
int result = doSomething(&x, &y);
// Output Results
cout << endl << "Modified value of x: " << x << endl;
cout << "Modified value of y: " << y << endl;
cout << "Sum of modified values: " << result << endl;
return 0;
}
// Function using pointers instead of reference variables
int doSomething(int* x, int* y)
{
int temp = *x;
*x = *y * 10;
*y = temp * 10;
return *x + *y;
}