December 3rd, 2012, 05:53 AM

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;
}}
}
}
December 3rd, 2012, 06:02 AM

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
}
December 3rd, 2012, 06:16 AM

thank you for the quick answer but IN[n]<=4 do what??
December 3rd, 2012, 06:39 AM

> 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!?
December 3rd, 2012, 07:22 AM

Your answer is very general and wrong!
December 3rd, 2012, 07:37 AM

Well I guess that's a function of your vague and illdefined 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