Pointer function help

Jul 1, 2013 at 4:54am
The assignment is : 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;
}

what am i doing wrong when calling the function? when i compile it doesnt work correctly

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
 #include <iostream>
#include <cstdlib>
using namespace std;
int dosomething();

int dosomething(int* x, int* y)
{
      int temp = *x;
      *x = *y * 10;
      *y = temp * 10;
      return *x+*y;
}

int main ()
{
int x,y;
cout << "Please enter a number" << endl;
cin >> x;
cout << "Please enter another number" << endl;
cin >> y;





dosomething(&x, &y);
cout << (x + y) << " = x(" << x << ") + y(" << y << ")\n" << endl;
system("Pause");
return 0;
}

Jul 1, 2013 at 5:12am
What leads you to believe it isn't working correctly? What data are you trying with it, what are you getting out, and what are you expecting?
Topic archived. No new replies allowed.