Returning Values

I'm writing a program for school in which the user must give 2 numbers and then the program will return the two numbers telling which one is the lowest.

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

void FindLOHI(int x, int y, int &lo, int &hi)
{
if(x < y)
	x=lo;
	y=hi;
if(x > y)
	x=hi;
	y=lo;

cout<< hi <<endl; //
cout<< lo <<endl; //for some reason these two integers return ridiculous   numbers in the 30,000s.
}

int main()
{
int x=23, y=28, lo, hi;
FindLOHI(x,y,lo,hi);
cout<<"LO="<< lo <<endl;
cout<<"HI="<< hi <<endl;
system ("PAUSE");
return 0;
}
Last edited on
You never set lo and hi to anything, so all they'll contain is garbage from the last program that run. Maybe you meant to have your assignments go the other way on lines 9, 10, 12, and 13?

By the way, you're missing something on those lines. How is the if supposed to know which statements it's supposed to execute?

-Albatross
Last edited on
Thanks, I had my assignments backyards, after i switched them it worked.
Topic archived. No new replies allowed.