Program is adding when it shouldn't be.

Hello, my problem is in my second function where the math is happening I am getting the wrong sum. I tried using the same code in simplified program and I got the correct answer. Whenever I try and enter the number 5 I should get the value of x as 5. Instead it comes out to 1 for some reason. What is the problem with my code? Or can someone point me in the right direction? Thank you in advance!

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
33
34
35
36
37
38
39
40
41
42
43
44
45
  #include <iostream>

using namespace std;


void initialize(int x, int & y);
void funcOne (int number, int & x, int & y);
void printxy (int x, int y);

int main()
{
   int number;
   int x, y;
   double rate, hours;
   double amount;

    initialize(x, y);
    funcOne(number, x, y);
    printxy(x, y);
    return 0;
}

void initialize(int x, int & y)
{
    x = 10;
    y = 20;
    cout << "x = " << x << endl;
    cout << "y = " << y << endl;
}

void funcOne (int number, int & x, int & y)
{
    cout << "Enter a number." << endl;
    cin >>  number;

    x = x*2 - y + number;
}

void printxy (int x, int y)
{
    cout <<"The new value of x is: " << x << endl;
    cout <<"The new value of y is: " << y << endl;
}

1
2
3
4
5
6
7
void initialize(int x, int & y)
{
    x = 10;
    y = 20;
    cout << "x = " << x << endl;
    cout << "y = " << y << endl;
}


Should be :
1
2
3
4
5
6
7
void initialize(int &x, int & y)
{
    x = 10;
    y = 20;
    cout << "x = " << x << endl;
    cout << "y = " << y << endl;
}
Such a simple fix. Thank you!
Topic archived. No new replies allowed.