Troublesome output placement

I have the entire program down, but I'm having a small problem with the output. The program is asking for two numbers to be inputted while separated by a space, and then displayed in order of largest to smallest. For some reason I can't get the output to go in the correct spot. Please see the screen shot and the code. Thanks in advance.

Screenshot:
http://img205.imageshack.us/img205/1925/minmax.jpg

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
46
47
48
49
50
51

#include <iostream>

using namespace std;

//declaration
int larger();
int smaller();

int num, ber, high, low;

int main()
{
    cout << "Welcome to the Min/Max Program.\n";
    cout << "You will be asked to enter two integers and this program will display\n";
    cout << "the larger and the smaller of the two.\n\n";

    cout << "Please enter two integers: "; cin >> num >> ber;
   
 high = larger();
    cout << "\nThe larger of the two integers is: " << high << "\n";
    
 low = smaller();
    cout << "The smaller of the two integers is: " << low << "\n\n";
    
    return 0;
}

int larger()
{
	{
	if (num > ber)
	cout << num;
	else
	cout << ber; 
	}
	
	return high;
}

int smaller()
{
	{
    if (ber < num)
	cout << ber;
    else 
	cout << num;
	}

	return low;
}
Last edited on
Read carefully these lines from your code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 high = larger();
    cout << "\nThe larger of the two integers is: " << high << "\n";
//...

int larger()
{
	{
	if (num > ber)
	cout << num;
	else
	cout << ber; 
	}
	
	return high;
}

The only thing I could think of is removing the high = larger(); line. That's the only thing that seems off to me. I did try that, and other various attempts, but wasn't able to find a solution.

Also, I'm not sure if I'm using the return high; command in a proper way.
Cute little tricks (like naming two variables "num" and "ber") are never a good idea in programming. Try n1 and n2. At any rate, you are not assigning high to anything in your subroutines. You don't want cout<<n1;, but high=n1;

Also, for proper style you should be using local variables in main and passing arguments to the functions.
Thank you, I appreciate the help.
Topic archived. No new replies allowed.