My os: win2000
My compiler: MS Visual C++ 6.0
My computer: Desktop
No matter what I do I cannot get this program to display the result in descending order. I want to display the result in order from the highest value to the lowest including the corresponding month.
My codes below:
// last updated Jan 06, 2002
// Purpose of this program: display a list of months and values,
// sorted the order from highest value to lowest
#include <iostream>
using namespace std;
void main(void)
{
char months[12][10] = {"January", "February", "March", "April",
"May", "June", "July", "August",
"September", "October", "November", "December"};
float r_fall[12]; // store data in each element of the array
for(int index=0; index<12; index++)
{
cout<<"Please enter rainfall amount for " <<months[index] <<": ";
cin>>r_fall[index];
while (r_fall[index] < 0)
{
cout<<"The data you entered is not a positive value: ";
// flush bad data input
// put a flush stmt. on next line
cout<<"re-enter a rainfall amount for "<<months[index] << ": ";
cin>>r_fall[index];
} // end of "while"
} // end of "for"
// hold on to this code --->Sort_Rainfalls(r_fall, months);
// sort rainfalls and produce a report
// sort the data in each element of the array
// need codes for the sort . Bubble sort might not work
// cout.precision(2); //optional
// cout.setf(ios::fixed|ios::showpoint); // optional
cout << "\nThe rainfall in descending order (from highest to lowest)" << endl;
for(int count=0; count<12; count++) //in ascending order
//original for(int count=12; count>0; count--)
{
cout << "Rainfall for" << " " << months[count] << ": " << r_fall[count] << " inches" << endl;
}
} // end of main
// ERROR list
// none
============================
The result that I got:
Please make sure you enter a positive whole or decimal value
Please enter rainfall amount for January: 5
Please enter rainfall amount for February: 3
Please enter rainfall amount for March: 8
Please enter rainfall amount for April: .88
Please enter rainfall amount for May: .44
Please enter rainfall amount for June: .33
Please enter rainfall amount for July: 7
Please enter rainfall amount for August: 12
Please enter rainfall amount for September: 32
Please enter rainfall amount for October: 45
Please enter rainfall amount for November: 33
Please enter rainfall amount for December: 5
The rainfall in descending order (from highest to lowest)
Rainfall for January: 5 inches
Rainfall for February: 3 inches
Rainfall for March: 8 inches
Rainfall for April: 0.88 inches
Rainfall for May: 0.44 inches
Rainfall for June: 0.33 inches
Rainfall for July: 7 inches
Rainfall for August: 12 inches
Rainfall for September: 32 inches
Rainfall for October: 45 inches
Rainfall for November: 33 inches
Rainfall for December: 5 inches
Press any key to continue
as you can see the values and the months are only in ascending order.
Help please !!!!!!!!