### Parallel Arrays

Working on a class problem involving parallel arrays.
We have to write a program which will give us total products sold, which of the seven products sold best and worst.

I have the code written, but I am getting snagged on one undefined identifier at line 89: "pos".

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687`` ``````#include #include #include using namespace std; int getTotal(int[], int); int posOfSmallest(int[], int); int posOfBiggest(int[], int); int main() { const int NUM_KINDS = 7; int sales[NUM_KINDS]; string name[NUM_KINDS] = { "mild", "medium", "hot", "sweet", "fruit", "verde", "zesty" }; int totalJarsSold, loSalsaSales, hiSalsaSales; for (int kind = 0; kind < NUM_KINDS; kind++) { cout << "Jars of" << name[kind] << "Sold Last Month" << ": "; cin >> sales[kind]; while (sales[kind] < 0) { cout << "Jars Sold Should Be 0 or More!" << " " << "Please Try Again: "; cin >> sales[kind]; } } totalJarsSold = getTotal(sales, NUM_KINDS); loSalsaSales = posOfSmallest(sales, NUM_KINDS); hiSalsaSales = posOfBiggest(sales, NUM_KINDS); cout << "Reported Salsa Sales\n\n" ; cout << "Name Jars Sold\n "; cout << "____________________________\n"; cout << name[0] << "Mild " << sales[0] << "\n"; cout << name[1] << "Medium " << sales[1] << "\n"; cout << name[2] << "Hot " << sales[2] << "\n"; cout << name[3] << "Sweet " << sales[3] << "\n"; cout << name[4] << "Fruit " << sales[4] << "\n"; cout << name[5] << "Verde " << sales[5] << "\n"; cout << name[6] << "Zesty " << sales[6] << "\n"; cout << "Total Sales: " << setw(15) << totalJarsSold << endl; cout << "Top Seller" << name[hiSalsaSales] << endl; cout << "Bottom Seller" << name[loSalsaSales] << endl; system("pause"); } int getTotal(int array[], int numElts) { int total = 0; for (int kind = 0; kind < numElts; kind++) total += array[kind]; return total; } int posOfBiggest(int array[], int numElts) { int indexOfBiggest = 0; for (int pos = 1; pos < numElts; pos++); { if (array[pos] > array[indexOfBiggest]) indexOfBiggest = pos; } return indexOfBiggest; } int posOfSmallest(int array[], int numElts) { int indexOfSmallest = 0; for (int pos = 1; pos < numElts; pos++); { if (array[pos] < array[indexOfSmallest]) indexOfSmallest = pos; } return indexOfSmallest; }``````
Last edited on
 I am getting snagged on one undefined identifier at line 89: "pos".

You have no line 89 in what you posted.

Line 69, 81: Remove the ; That terminates the `for` loop causing pos to go out of scope and not be visible to subsequent lines.

Last edited on
Sorry about the missing lines, I didnt put the classroom header in the code copy.

I knew it was something small lol. Thank you.

Topic archived. No new replies allowed.