// order.cpp
//
// Debugging exercise
#include <iostream>
using namespace std;
void order(int& a, int b);
/*
* int main()
*
* Displays values of two variables both before and
* after the value of those variables are swapped
* via a call to a swap function.
*
* Global variables:
* cin - an istream object for input from the keyboard.
* cin is an external variable, declared
* in library header file <iostream>.
* cout - an ostream object for output to the terminal.
* cout is an external variable, declared
* in library header file <iostream>.
*/
int main()
{
// Announce purpose of program:
cout << "This program will print, in numerical order, ";
cout << "2 integers you enter in any order." << endl;
cout << "Enter an integer:>";
int number1;
cin >> number1;
if ( !cin ) {
cout << "You must enter integers only." << endl;
return 1;
} // if
cout << "Enter another integer:>";
int number2;
cin >> number2;
if ( !cin ) {
cout << "You must enter integers only." << endl;
return 1;
} // if
// Rearrange the numbers in numerical order,
// if they are not already in numerical order:
order(number1, number2);
// Print the numbers:
cout << "The numbers you entered are, in numerical order: ";
cout << number1 << " and " << number2 << "." << endl;
return 0;
} // function main
/*
* void order(int& a, int b)
*
* Puts a pair of integers in numerical order.
*
* Parameters:
* a - a reference to an integer.
* Preconditon: a has been given any int value.
* Postcondition: a has the previous value of b,
* if b was previously less than a.
* Otherwise, a is unchanged.
* b - a reference to another integer.
* Preconditon: b has been given any int value.
* Postcondition: b has the previous value of a,
* if a was previously greater than b.
* Otherwise, b is unchanged.
*/
void order(int& a, int b)
{
if ( a > b ) {
int temp = a;
int a = b;
b = temp;
} // if
} // function order