I am creating program with parrallet arrays and when the three arrays are sorted by selection sort they need to stay parallel, but I am haveing trouble doing this in the dualsort function. Thank YOu!


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

// Function Prototypes
void calcSales(int [], double [], double [], int);
void showOrder(double [], int [], char[][30], int);
void dualSort(int [], double [], char[][30], int);
void showTotals(double [], int [], int);

// NUM_PRODS is the number of products produced.
const int NUM_PRODS = 9;

int main()
{
	int id[NUM_PRODS] = {914, 915, 916, 917, 918, 919, 920, 921, 922};
	int units[NUM_PRODS] = {842, 416, 127, 514, 437, 269, 97, 492, 212};
	double prices[NUM_PRODS] = {12.95, 14.95, 18.95, 16.95, 21.95, 31.95, 14.95, 14.95, 16.95};
	double sales[NUM_PRODS];
	char productNames[NUM_PRODS][30] = { "Lego","Thomas", "Dora", "Doodle", "Bratz", "Magnetix", "Wagon", "Drums", "DollHouse"}; 

	calcSales(units, prices, sales, NUM_PRODS);
	dualSort(id, sales, productNames, NUM_PRODS);
	cout.precision(2);
	cout.setf(ios::fixed | ios::showpoint);
	showOrder(sales, id , productNames, NUM_PRODS);
	showTotals(sales, units, NUM_PRODS);
	return 0;
}

/*	Definition of calcSales.  Accepts units, prices, and sales arrays as arguments.
	The sized of there arrays is passed into the num parameter. This function calculates
	each product's sales by multiplying its units sold by each unit's price.  The result is
	stored in the sales array.
*/

void calcSales(int units[], double prices[], double sales[], int num)
{
	for ( int index = 0; index < num; index++)
	{
		sales[index] = units[index] * prices [index];
	}
}

/* Definition of function dual Sort.  Accepts id an sales arrays as arguments.  The size
	of these arrays is passed into elems.  This function performs a descending order selection sort
	on identically as those of the sales array.  elems is the number of elements in each array.
*/

void dualSort(int id[], double sales[], char productNames[][30], int elems)
{
	int startScan, maxIndex, tempid1;

	string tempid2;
	double maxValue;

	for(startScan = 0; startScan < (elems -1); startScan++)
	{
		maxIndex = startScan;
		maxValue = sales[startScan];
		tempid1 = id[startScan];
		tempid2 = productNames[startScan][30];
		for(int index = startScan+1; index < elems; index ++)
		{
			if (sales[index] > maxValue)
			{
				maxValue = sales[index];
				tempid1 = id[index];
				tempid2 = productNames[index][30];
				maxIndex = index;
			}
		}
		
		sales[maxIndex] = sales[startScan];
		id[maxIndex] = id[startScan];
		productNames[maxIndex][30] = productNames[startScan][30];
		sales[startScan] = maxValue;
		id[startScan] = tempid1;
	
	}
}
/*	Definition of showOrder function. Accepts sales and id arrays as arguments.  The size of these arrays is passed into num.
	The function first displays a heading, then the sorted list of products numbers and sales.
*/
void showOrder(double sales[], int id[], char productNames[][30],int num)
{
	cout << "Product Number\t  Product Name          Sales\n";
	cout << "---------------------------------------------------\n";
	for ( int index = 0; index < num; index++)
	{
		cout << id[index] <<"\t\t  "<< productNames[index]<< "  \t\t$";
		cout <<setw(8) << sales[index] << endl;
	}
	cout << endl;
}

/*	Definition of showTotals function.  Accepts sales and id arrays as arguments.  
	The size of these arrays is passed into num. The function first calculates 
	the total units (of all products) sold and the total sales.  It then displays these ammounts.
*/
void showTotals(double sales[], int units[], int num)
{
	int totalUnits = 0;
	double totalSales  = 0.0;

	for (int index = 0; index < num; index++)
	{
		totalUnits += units[index];
		totalSales += sales[index];
	}
	cout << "Total units Sold: " << totalUnits << endl;
	cout << "Total sales:	 $" << totalSales << endl;
}