ARRAY PRACTICE

I am supposed to write a program that uses two parallel arrays, one of which is an array that contains the "type of salsas" and the other contains the amount of sales for said salsas as entered by the user. After the user enters the information, the program sorts the number of sales in descending order along with the type of salsa from the salsa string array. I am having trouble outputting the actual strings with the number of salsa units sold. Any help is appreciated! Here is my code so far..
#include<iostream>
#include<string>
using namespace std;

void getSalsaSales(int salsaCost[5]);
void salsaSorter(int salsaCost[5], int jive, string salsaVariant[5]);

int main() {
int const length = 5;
string salsaVariant[length]= {"mild", "medium", "sweet", "hot", "zesty"};
int salsaCost[length];

getSalsaSales(salsaCost);
salsaSorter(salsaCost, length, salsaVariant);

system("pause");
return 0;
}

void getSalsaSales(int salsaCost[5]) {
for (int i = 0; i < 5; i++) {
cout << "Please enter the amount of bottles sold for salsa type #" << i + 1 << endl;;
cin >> salsaCost[i];
while (salsaCost[i] < 0) {
cout << "ERROR: Entry must be a positive integer!" << endl;
cout << "Please enter a valid input for salsa #" << i + 1
<< endl;
cin >> salsaCost[i];
}
}
}

void salsaSorter(int salsaCost[5], int jive, string salsaVariant[5]) {
int i = 0, jiveTurkey;
bool jiving;
do {
jiving = false;
for (int i = 0; i < jive - 1; i++) {
if (salsaCost[i] < salsaCost[i + 1]) {
jiveTurkey = salsaCost[i];
salsaCost[i] = salsaCost[i + 1];
salsaCost[i + 1] = jiveTurkey;
jiving = true;
}
}
} while (jiving);
for (i = 0; i < 5; i++)
cout << "The order from most to least is: " << salsaCost[i] << endl;
//for (i = 0; i < 5; i++)
//cout << salsaVariant[jive]; THIS IS WHERE IM LOST
}
When sorting your arrays you need to swap the items in both arrays.
Great got it. Thanks for the help!
Or if you don't want to swap around a bunch of strings, you can have a third array that starts as a series of numbers, and then swap those instead. then when reporting them, embed the array within the other array...

int salsaNum[5]={0,1,2,3,4};
to go along with your salsaCost array as the parallel array.

As you swap things in your sort,
salsaSales[numb] will contain the sales data for salsaVariant[salsaNum[numb]]


Topic archived. No new replies allowed.