I am currently writing a program for a homework assignment, but I seem to be encountering an error. The question asks:
The following function uses reference variables as parameters. Rewrite the function so it uses pointers instead of reference variables, and then demonstrate the function in a complete program.
int doSomething(int &x, int &y)
{
int temp =x;
x = y * 10;
y = temp * 10;
return x + y;
}
I understand how to covert the reference variables to pointers, however I am stuck on this error. Either I get the error listed in the title or (with a few changes) the error "invalid conversion from 'int' to 'int*'"
#include <iostream>
usingnamespace std;
int doSomething(int*, int*);
int main()
{
int X, Y, result;
int* ptr_x = X;
int* ptr_y = Y;
cout << "What is your value for x?\nIntegers only.\n";
cin >> *ptr_x;
cout << "What is your value for y?\nIntegers only.\n";
cin >> *ptr_y;
cout << "Now I will do something to the numbers!\n";
result = doSomething(ptr_x, ptr_y);
cout << "I have multiplied both x and y by 10 and then added them together!\nHere is the result " //I really didn't know how else to use the "doSomething" function in a meaningful way. So... I just stated what the function does.
<< result << ".\n";
system("PAUSE");
return 0;
}
int doSomthing(int *x, int *y)
{
int temp = *x;
*x = *y * 10;
*y = temp * 10;
return *x + *y;
}