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