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".


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <iostream>
#include <iomanip>
#include <string>

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.