Ok, I'm sitting here in my CIS class trying to figure out how to move words put in my character array. The program is, sorting the monthly rainfall in order from highest to lowest, organizing the months along with it. I have one array of ints and another character array. This is the code i have. I am having trouble moving the words to another part of the array. Here is my exact code.
// Written by Ryan Dillon
// November 30, 2004
// Chapter 8
// Assignment 3, Rainfall Statistics Modification
#include <iostream>
#include <conio.h>
#include <iomanip>
using namespace std;
void selectionSort(int[], char[12][10], int);
void showArray(int[], char[12][10], int);
int main()
{
int month[12], total = 0, smallest = 9999, largest = -1;
int count;
char months[12][10] = {"January", "February", "March",
"April", "May", "June",
"July", "August", "September",
"October", "November", "December"};
cout << "Please enter the total rainfall for each month." << endl;
for (count = 0; count < 10; count++)
month[count] = -1;
for (count = 0; count < 10; count++)
{
cout << months[count] << ": ";
cin >> month[count];
if (month[count] < 0)
cout << "Please enter positive values only.";
}
showArray(month, months, 12);
getch();
return 0;
}
void selectionSort(int array[], char months[12][10], int elems)
{
int startScan, maxIndex, maxValue, index;
char tempMonth[12][10];
for (startScan = 0; startScan < (elems - 1); startScan++)
{
maxIndex = startScan;
maxValue = array[startScan];
tempMonth = months;
for(index = startScan + 1; index < elems; index++)
{
if (array[index] > maxValue)
{
maxValue = array[index];
maxIndex = index;
}
}
array[maxIndex] = array[startScan];
months[maxIndex] = months[startScan];
array[startScan] = maxValue;
months[startScan] = tempMonth[maxIndex];
}
}
void showArray(int array[], char months[12][10], int elems)
{
int index;
for (index = 0; index < elems; index++)
cout << months[index] << "\t" << array[index] << endl;
}
so uh... help :mrgreen:
this is my first post btw, im glad i found a good c++ forum!