How to sort the numbers in a random number generator

I am needing help sorting the numbers that the random number generator puts out.
I have to create a vector, size 20. Display that vector. Sorts the vector and displays the resorted vector.

The other thing that my code has to do is creates a txt file of the output using command line redirection. But, i am not necessarily worried about this part yet.

This is my first post.

This is what I have so far:

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 <conio.h>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	vector <int> vector;
	int i = 0;
	while (i++ < 20) //This is where you define how many numbers you want randomly generated
	{
		int r = (rand() % 100 + 0); //this is where you define what potential numbers you want generated.
		// In this case, the numbers 0-100 are being used
		cout << r << " ";
		
	}

	cout << "Press any key to quit.";

	_getch();
	return 0;
}//end main 

Last edited on
http://www.cplusplus.com/reference/algorithm/sort/

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
Topic archived. No new replies allowed.