I need help with a hw assignment!!!!

closed account (L86bpfjN)
Your company has set up a contest to raise money for a local charity. Each department is selling boxes of cookies, with the department that sells the most boxes winning a trip to see the Patriots play. You have volunteered to keep track of the sales. The sales figures are stored in a file which will be used for input to this program. You can download the file (boxes.txt) from Blackboard
and you can hard-code its name in your program.

Each record in the file has a department's ID number on it and the number of boxes sold. There will be multiple records for each department, as this data was collected over a several-week period. You decide to create parallel arrays: one to hold the department numbers and one to record the number of boxes sold (Note: do NOT use a 2-D array; this is about using parallel arrays). There are 15 departments in your company so you will need 15 elements in each array. It is possible that some departments may not participate, so the arrays may be only partially filled.

Here is a sample of the data:
Dept Boxes Sold
300 23
410 1
130 13
130 7
410 5
120 6

PROCESSING:

Read a dept number and the boxes sold from the file into 2 variables (both are ints). Don't put them into the arrays yet! Loop through elements of the dept number array to see if that dept is already there. (Note: you should only be checking the elements that have been used: So after you have 3 departments in the array, you will look only at those 3 elements to see if the input dept
number is there.)

 If the input dept number is already in the array, simply add the boxes sold to the corresponding element of the boxes sold array. So if you find the input dept number in the array at index 2, then add the boxes sold to the value in the boxes array at index 2).

 If the input dept number is not already in the dept array, put it into the first unused element of the dept number array, and put the boxes sold for that dept into the corresponding element of the boxes sold array. So if there were 3 departments in the array, and you now have a new department number, you would put the new dept number into the 4th element of the department array and you would put the boxes it sold into the 4th element of the boxes array.

Loop until you encounter the end of the input file

I'm having a hard time figuring out the code for the loop
Here is my code:

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
while (inputFile >> deptNum >> boxes)
	{
		
		while (count < NUM_DEPT)
		{
			if ( index < count)
			{
				if (deptId[index] == deptNum)
				{
					boxesSold[index] = boxesSold[index] + boxes;
					index--;
					count--;
				}
				else if ( deptId[index] != deptNum)
				{
					deptId[count] = deptNum;
					boxesSold[count] = boxes;
				}			
				index++;
			}
			else
			{
				deptId[count] = deptNum;
				boxesSold[count] = boxes;
			}	
			count++;
			break;
		}
	}	
Please HELP! Thank you
Last edited on
Please, use code tags (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your
post. http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <>
formatting button.
Topic archived. No new replies allowed.