#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2012
    Posts
    24
    Rep Power
    0

    Ignore a particular element?


    Hello,
    i have a small problem in this function code.I want when the IN[n]+1 become bigger than 4 to ignore in this particular n the P[n].VALUE and P[n].LINE.
    Can you help me?

    Code:
    int compair_value()
    {
    	int min,i,c,j;
    		for(n=0;n<4;n++){
    			IN[n]=0;
    		}
    		
    for(c=0;c<20;c++){
    	for(n=0;n<4;n++){
    		IN[n]=P[n].LINE;
    		P[n].VALUE=A[n][IN[n]];
    		}
    
    		min=P[0].VALUE;
    		for(j=0;j<4;j++){
    		if(min>P[j].VALUE)
    			{
    			min=P[j].VALUE;	
    			}}
    			for(n=0;n<4;n++){
    			if(min==P[n].VALUE){
    				P[n].LINE=IN[n]+1;
    				B[c]=P[n].VALUE;	
    				
    			}}
    			
    			}
    			
    }
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,366
    Rep Power
    1870
    It would help if you could indent code.
    Code:
    int compair_value()
    {
      int min, i, c, j;
      for (n = 0; n < 4; n++) {
        IN[n] = 0;
      }
    
      for (c = 0; c < 20; c++) {
        for (n = 0; n < 4; n++) {
          IN[n] = P[n].LINE;
          P[n].VALUE = A[n][IN[n]];
        }
        min = P[0].VALUE;
        for (j = 0; j < 4; j++) {
          if (min > P[j].VALUE) {
            min = P[j].VALUE;
          }
        }
        for (n = 0; n < 4; n++) {
          if (min == P[n].VALUE) {
            P[n].LINE = IN[n] + 1;
            B[c] = P[n].VALUE;
          }
        }
      }
    }
    > I want when the IN[n]+1 become bigger than 4
    So how about
    Code:
    if ( IN[n]+1 <= 4 ) {
       // do stuff
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2012
    Posts
    24
    Rep Power
    0
    thank you for the quick answer but IN[n]<=4 do what??
  6. #4
  7. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,366
    Rep Power
    1870
    > thank you for the quick answer but IN[n]<=4 do what??
    If you're asking that, how did you manage to write all that code to begin with!?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2012
    Posts
    24
    Rep Power
    0
    Your answer is very general and wrong!
  10. #6
  11. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,366
    Rep Power
    1870
    Well I guess that's a function of your vague and ill-defined question.

    We can't compile it, because you don't declare IN, or what the structure behind it is.
    We can't run it, because there is no data.

    Your vaguest of questions can only be interpreted as "how do I do an if statement". If you're still stuck, then read your C book.

    Then swing by here before asking another question
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper

IMN logo majestic logo threadwatch logo seochat tools logo