Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
December 3rd, 2012, 05:53 AM
 Giorgos
Registered User

Join Date: Feb 2012
Posts: 24
Time spent in forums: 6 h 27 m 36 sec
Reputation 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
December 3rd, 2012, 06:02 AM
 salem
Contributed User

Join Date: Jun 2005
Posts: 4,252
Time spent in forums: 2 Months 4 Weeks 1 Day 12 h 25 m 37 sec
Reputation Power: 1809
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
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

#3
December 3rd, 2012, 06:16 AM
 Giorgos
Registered User

Join Date: Feb 2012
Posts: 24
Time spent in forums: 6 h 27 m 36 sec
Reputation Power: 0
thank you for the quick answer but IN[n]<=4 do what??

#4
December 3rd, 2012, 06:39 AM
 salem
Contributed User

Join Date: Jun 2005
Posts: 4,252
Time spent in forums: 2 Months 4 Weeks 1 Day 12 h 25 m 37 sec
Reputation Power: 1809
> 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!?

#5
December 3rd, 2012, 07:22 AM
 Giorgos
Registered User

Join Date: Feb 2012
Posts: 24
Time spent in forums: 6 h 27 m 36 sec
Reputation Power: 0

#6
December 3rd, 2012, 07:37 AM
 salem
Contributed User

Join Date: Jun 2005
Posts: 4,252
Time spent in forums: 2 Months 4 Weeks 1 Day 12 h 25 m 37 sec
Reputation Power: 1809
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

 Viewing: Dev Shed Forums > Programming Languages > C Programming > Ignore a particular element?