// Andres Guzman CSC5 Chapter 9, P. 538, #5
/******************************************************************************
*
* REWRITE FUNCTION
* ____________________________________________________________________________
* Program will convert given function to be referenced using pointers
*
* Computation:
*
* Uses pointers to reference the variables, multiplies each referenced
* value by 10, and adds the modified values before returning the result.
* ____________________________________________________________________________
*
* INPUT
*
* input1 = Holds inputed value
* input2 = Holds inputed value
*
* OUTPUT
*
* answer = returned value of called function
*
******************************************************************************/
#include <iostream>
using namespace std;
int doSomething(int *x, int *y);
int main()
{
int input1; //Inputed Value of user
int input2; //Inputed Value of user
cout << "Enter a Value into Input 1: ";
cin >> input1;
while(input1 < 0) //Input Validation
{
cout << "Please Enter Valid Value." << endl;
cout << "Enter a Value into Input 1: ";
cin >> input1;
}
cout << "\nEnter a Value into Input 2: ";
cin >> input2;
while(input2 < 0) //Input Validation
{
cout << "Please Enter Valid Value." << endl;
cout << "Enter a Value into Input 2: ";
cin >> input2;
}
//
//Function Call and adds returned value to variable
int answer = doSomething(&input1, &input2);
//
//Output results
cout << "\nAnswer: " << answer;
return 0;
}
/******************************************************************************
* Adding definition to function. Function will use pointers to reference
* variables and multiply given variables and return their total value.
******************************************************************************/
int doSomething(int *x, int *y)
{
int temp = *x; //Temporarily holds x value
*x = *y * 10; //X value holds y value times 10
*y = temp * 10; //Y value holds temporary value times 10
return *x + *y; //Return value of x and y added
}