im trying to get this function to show the numbers that are not on the list in the input file, i've written this and it doesnt work, i know theres sometihng wrong with it but im not sure what it is? or how i can fix it to make it work or be more efficient

void not_part()
{
	ins.open(in_file);
	int i=0;
	int t=0;
	int j=0;
	int sum=0;
	cout<<"AGENTS WHO DID NOT PARTICIPATE IN THE CAMPAIGN"<<endl;
	cout<<fixed<<showpoint;
	cout<<setprecision(2);
	while(!ins.eof())
	{
		int agnt, sals;
		float val;
		ins>>agnt>>sals>>val;
		int row = FindAgent(agnt,i);
		if( row < 0)
		{
		   agent[i]=agnt;
		   sales[i]=sals;
		   value[i]=val;
		   amount[i]=sales[i]*value[i];
		i++;
		}
		else
		{
		   sales[row]+=sals;
		   sum=sals*val;
		   amount[row]+=sum;
		   value[row]=amount[row]/sales[row];
		}
	}
	
	for(int t=0; t<=count; t++)
		for(int h=1; h<=20; h++)
		{
		if((agent[t]!=h)||((value[t]=0)&&(amount[t]=0)))
			cout<<setw(2)<<agent[t]<<endl;
		}

	cout<<endl;
	ins.clear();
	ins.close();
}

int FindAgent(int agnt, int maxrow)
{
   for(int i = 0; i < maxrow; i++)
      if( agent[i] == agnt)
         return i;
   return -1;
}

line 37: use == operator, not = operator. That is setting those variables to 0.

This problem is what gave rise to the way I now code equality checks. Rather than if (i == 0) I put the manifest constant on the left if (0 == i) . Now, if I slip and use a single '=' rather then the required '==', the compiler catches it for me. To get this small but real benefit, which you get every time you code an equality test, you have to pay a very small price:

  • You have to retrain yourself to habitually put constants on the left
  • People think you are a little odd when they read your code

In my experienced opinion, that cost is trivial. I urge you to go and do likewise.

after making those changes i still cant get it to work, i tihnk i need to write a new loop for it, but how would i do this?? i need it to compare numbers from 1 - 20 and if its not there then to display it, mines just compares it to every input then displays if its not the same

If you think it would help, another option would be defining the equality operator as a macro.

#define is_equal_to ==

Ugh. You can do such things if you don't like the language, but in my opinion, you should use the language to its (and your) best advantage instead. For instance, does this make sense to you?

#define like {
#define yknow }
#define uh ;
#define whenever for
#define more ++
whenever (i=1 uh i < 5 uh more i) like cout << i << endl uh yknow

I thought not. Neither does any other gratuitous use of macros as syntactic sugar. Your "is_equal_to" took me two tries to type correctly, is 5.5 times longer then '==' and looks illegal to the trained programmer. I re-iterate: "Ugh!"

Comments
agree completly

i made this loop, but it doesnt work, its supposed to check the agent numbers in the input file and if it deosnt math and of the h's then should output, but it wont work, how can i fix it?

for(int h=1; h<=20; h++)
		for(int t=0; t<=count; t++)
		{
			if((h!=agent[t])||((0==value[t])&&(0==amount[t])))
				cout<<setw(2)<<agent[t]<<endl;
		}

Ugh. You can do such things if you don't like the language, but in my opinion, you should use the language to its (and your) best advantage instead. For instance, does this make sense to you?

#define like {
#define yknow }
#define uh ;
#define whenever for
#define more ++
whenever (i=1 uh i < 5 uh more i) like cout << i << endl uh yknow

I thought not. Neither does any other gratuitous use of macros as syntactic sugar. Your "is_equal_to" took me two tries to type correctly, is 5.5 times longer then '==' and looks illegal to the trained programmer. I re-iterate: "Ugh!"

Better not look into iso646.h then, lol.

Better not look into iso646.h then, lol.

Because my life is clean and my cause just, I get to use a regular ASCII keyboard... iso646.h is way nicer than trigraphs...

This article has been dead for over six months. Start a new discussion instead.