putting two integers in incremental order

Hey peeps.
we were given this probe: The program
prompts the user to enter any to integers. The two integers must be displayed in
incremental order. A call to the function “simplesort” is made. You may not change the
given code, you may only create and implement the function “simplesort”.


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
//overloading
#include <iostream>
using namespace std;

void simplesort(int &,int &);

int main()
{
     cout << "Enter any two integers: " << endl;
     int smaller, larger;
     cin >> smaller;
     cin >> larger;
  
     //At this stage it is not necessarily the case that the smaller of the two
     // values are stored the variable named "smaller".

     simplesort(smaller, larger); //You should create this function
	
     //At this stage the smaller of the two values must to stored in "smaller" and
     // the larger of the two in "larger"
	
     cout << "The values in incremental order are: " <<
		smaller << " " << larger << endl;
     return 0;
}

void simplesort(int &small, int &large)
{
					
	    if(small > large)
		{
			small = large;
			large = small;
		}
}


i tried everything i could and i always get the numbers as i inputted them in or i get something like" 3 3" if i entered '6' and '3'.
you help wil be really appreciated:-)
1
2
			small = large;
			large = small;

You might want to reproduce what's happening here with pen and paper.
correct me if im wrong but the way i think i understand this probe is that should i not check to see which is bigger between the two then assign each to its 'names', which in this case are small and large.....that is what i was trying to do
I didn't really understand a single word of what you said, but here are two numbers:
small=5, large=3
Now go through the simplesort function line by line to see what happens.
Topic archived. No new replies allowed.