Checking Array entries

Hello, I am working on this problem with no luck. I have a list of data that has been put into an array like so

a[0] = 2
a[1] = 3
a[2] = 6
a[3] = 8
a[4] = 10
a[5] = 12

The numbers correspond to employees id's who participated in a fundraiser. I have 20 employees in total. Therefore I am trying to check the array to see out of the 20 employees who did not participate. In this case it would be 1,4,5,7,9,11,13,14,15,16,17,18,19,20.

I was trying something like this
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
ins.open(in_file);
	int i =0;
	while (!ins.eof())
	{
	ins >> agent[i] >> sales[i] >> value[i];
	i++;
	}
	
	for (int r = 0; r<i; r++)
	{
		for (int x=1; x<20; x++)
		{
			
			cout << x << endl;
		
		}

}

but it prints out x every time it checks so I get like 20 x i amount of numbers.... help ?
thanks
1
2
3
4
5
6
7
8
9
10
11
 file.open(where you want it); // opens file 
for(int i = 0; file.good(); i++) file >> agentID[i];  // uploaded the id numbers
file.close(); //remember to close file
std::vector<int> not_addented; // vector can use arrays if you want. 
for(int i = 0; i < 20; i++){ // moves agentID 
for(int j = 0; j < 20; j++){ // moves array a
if(agentID[i] == a[j]){ // if they equal each other do next statement
not_addented.push_back(agentID[i]); break; // adds element to end of vector that records the value of each match. 
}
}
} 

Okay I think I see where your going with this.. But I haven't learned vectors yet. Is there a different way to do it ?
Like so:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
ins.open(in_file);
	int i =0;
	while (!ins.eof())
	{
	ins >> agent[i] >> sales[i] >> value[i];
	i++;
	}
	
	for (int x=1; x<20; x++)
	{
		bool participate = false;
		for (int r = 0; r<i; r++)
		{
			if(agent[r] == x)
			{
				participate = true;
				break;
			}
		}
		if(! participate)
			cout << x << endl;

}
Awesome thanks ! got it to work ... realized I had closed file input in previous function.. seemed to be one of my problems... My Next problem is this.... I am suppose to add up the sales from each employee and out the top three however, I have to add to employee ID's together..

this is my input
First column employee ID, second sales, third value of each unit

1	3	250
2	0	0
15	1	1000	
3	4	300
12	2	500
1	2	300
3	4	115
21	3	400
-1	4	250
15	1	200
9	5	-150
18	2	140
13	2	550



so as you can see employee 1 makes two different sales.. How do I calculate the amounts and combine both of employee 1's sales.. this is what I have.. but. it only sorts the list as is..

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
ins.open(in_file);
	int i=0;
	int temp, temp2;
	bool swap;
	int winnersAmount[20] ={0};

	while (!ins.eof())
	{
	ins>> agent[i] >> sales[i] >> value[i];
	if ((agent[i] > 0) && (agent[i]<20) && (sales[i] >0) && (value > 0))
	{
	winnersAmount[i] = sales[i] * value[i];
	}
	
	i++;
	}
	
	
	do 
	{
		swap = false;
		for (int count = 0; count < (i-1); count++)
		{
			if (winnersAmount[count] < winnersAmount[count + 1])
			{
				temp = winnersAmount[count];
				temp2 = agent[count];
				winnersAmount[count] = winnersAmount[count + 1];
				agent[count] = agent[count + 1];
				winnersAmount[count + 1] = temp;
				agent[count +1] = temp2;
				swap = true;
			}
		}
	}while (swap);

	cout << "THE TOP THREE WINNERS ARE:" << endl;
	cout << "AGENT\t" << "AMOUNT\n";

		for (int r = 0; r<3; r++)
	{	

	cout <<agent[r] <<"\t" << winnersAmount[r] << endl;
		}
		ins.clear();
		ins.close();
}
Last edited on
Topic archived. No new replies allowed.