1. ## sorting

What am I doing wrong with this sorting algorithm? The months aren't being displayed properly.

Code:
```#include <iostream>
#include <string>
using namespace std;

void sort(int arry[], int size);

int main()
{
string months[] = {"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"};

int    rainfall[12];

int highest = INT_MIN;
int lowest  = INT_MAX;

int high;
int low;

cout << "Enter the monthly rainfall for each month" << endl;

for (int i = 0; i < 12; i++)
{
cout << months  [i] << ": ";
cin  >> rainfall[i];

if (cin.fail() || rainfall[i] < 0)
{
cin.clear();
cin.ignore(INT_MAX, '\n');

cout << "Error...re-enter..." << endl;
cout << months  [i]           << ": ";
cin  >> rainfall[i];
}

if (rainfall[i] > highest)
{
highest = rainfall[i];
high   = i;
}

if (rainfall[i] < lowest)
{
lowest = rainfall[i];
low    = i;
}

sort(rainfall, 12);
}

cout << "\nThe month with the highest rainfall is "
<< months[high]             << endl;

cout << "\nThe month with the lowest rainfall is "
<< months[low]              << endl;

cout << "\nHere are the months sorted from highest rainfall"
<< " to smallest rainfall:" << endl;

for (i = 0; i < 12; i++)
cout << months[high--]       << endl;

return 0;
}

void sort(int array[], int size)
{
int swap;
int temp;

do
{
swap = 0;

for (int i = 0; i < size - 1; i++)
{
if (array[i] > array[i +1])
{
temp         = array[i];
array[i]     = array[i + 1];
array[i + 1] = temp;
swap         = 1;
}
}
} while (swap != 0);
}```

2. cout << months[high--] << endl;

Should be:

cout << months[i] << endl;

3. Originally posted by XSquared
cout << months[high--] << endl;

Should be:

cout << months[i] << endl;
That doesn't work either. Your way just sorts the months from the first month to the last month. I'm trying to sort them by which month has the highest rainfall to the month with the smallest rainfall.

4. Code:
```void sort(int array[], string array2[], int size)
{
int swap;
string tempS;
int temp;

do
{
swap = 0;

for (int i = 0; i < size - 1; i++)
{
if (array[i] < array[i +1])
{
tempS         = array2[i];
array2[i]     = array2[i + 1];
array2[i + 1] = tempS;
temp         = array[i];
array[i]     = array[i + 1];
array[i + 1] = temp;
swap         = 1;
}
}
} while (swap != 0);
}```
And make sure to pass months as the 2nd parameter.