Making array into descending order with Loops or Sorting

Hey guys, I am new to this forum and I really need some help. I have looked at the information on sorting and I just can't get it.

What I need to do, is to make the numbers the user inputs into the array printed from the greatest one to the least (descending order). I think this can be done with either loops or sorting but I don't get it at all. If anyone can help, I will appreciate it.

Here is my code so far in C++

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
// array.cpp
#include <iostream.h>

main()
{
 const int array_size = 100000;
 int num_values, index, number[array_size];

 cout << "How many numbers are you going to input? ";
 cin >> num_values;

 for(index = 1; index <= num_values; index++)
 {
  cout << "Enter the number for #" << index << ": ";
  cin >> number[index];
 }

 cout << "This is what you entered: ";

 for(index = 1; index <= num_values; index++)
 {
  cout << number[index] << " ";
 }

 return 0;
}
Last edited on
If you would have entered "sorting" into the text-box that has the word "search" attached to its left side, the sixth entry you would have gotten after pressing the commandbutton called "search" might have helped you quite a bit.

I, and I guess I am not alone with this attitude, do not like to post the same code-example every other day. So, please, try the search-function first.

int main
Or, my all time favorite, check
http://en.wikipedia.org/wiki/Quicksort
Topic archived. No new replies allowed.