Quick question

Hey I have a my programming lab question here and I just don't know what's wrong.

This is the question:

Write the definition of a function named maxmin that is passed four int arguments . The function returns nothing but stores the larger of the first two arguments in the third argument it receives and the the smaller of the first two arguments in its fourth argument . So, if you invoke maxmin(3,7,x,y) , upon return x will have the value 7 and y will have the value 3.

When inputing:
7
3
0
0

It outputs 7333
when it should output 7373

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
#include <iostream>
using namespace std;

void maxmin (int, int, int&, int&);

int main ()
{
    int a, b, x, y;
    cin >> a >> b >> x >> y;
    maxmin(a,b,x,y);
    cout << a << b << x << y;
    
}

void maxmin ( int a, int b, int &x, int &y)
{
	if (a > b)
	{
		x = a;
		y = b;
	}
	else
		y = a;
                x = b;
}
I suggest you use braces for all your control statements, even if not technically required.

Also you really don't need to input the x and y values from the user, just initialize them to some known value.

Ahhhhh! Yes it was my lack of curly brackets on the the else statement. D'oh
Thanks man.
Topic archived. No new replies allowed.