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.
#include <iostream>
#include <cmath>
#include <cstdlib>
usingnamespace 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;
}
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?