I have been struggling with this all day, the output I get is all correct execept the middle result. If anyone can help me it would be great. The output I get is for id[A] instead of id[C], it seems like in the loop the ID for A is carried to C.
int firstA=0, firstS=0, secondS=0, firstC=0, secondC=0;
for (row=0; row<totalSize; row++) {
if (category[row]=='A' && ranking[firstA] < ranking[row]) {
firstA = row;
}
if (category[row]=='C' && ranking[firstC] < ranking[row]) {
secondC = firstC;
firstC = row;
}
else if (category[row]=='C' && ranking[secondC] < ranking[row]) {
secondC = row;
}
if (category[row]=='S' && ranking[firstS] < ranking[row]) {
secondS = firstS;
firstS = row;
}
else if (category[row]=='S' && ranking[secondS] < ranking[row]) {
secondS = row;
}
}
printf("A : %d %.2lf \n", id[firstA], ranking[firstA]);
printf("C : %d %.2lf \n", id[firstC], ranking[firstC]);
printf("C : %d %.2lf \n", id[secondC], ranking[secondC]);
printf("S : %d %.2lf \n", id[firstS], ranking[firstS]);
printf("S : %d %.2lf \n", id[secondS], ranking[secondS]);
return 0;
}
INPUT FILE
10
14 A 447 252 68 34 978
2 C 230 299 597 180 9
27 A 318 220 97 28 1317
32 C 563 450 547 112 28
8 C 669 260 200 36 171
11 S 179 45 1342 732 174
19 S 74 249 861 1165 6
21 A 757 240 97 119 2032
15 S 275 177 588 577 52
6 C 886 401 327 109 48
EXPECTED OUTPUT
A: 21 1171.00
C: 6 696.70
C: 32 578.00
S: 11 1094.20
S: 19 1046.50
The problem is here, I get this
A : 21 1171.00
C : 6 696.70
C : 14 601.10
S : 11 1094.20
S : 19 1046.50
The Middle C is carrying the ID of one of the A's. I can't seem to figure out whats wrong in my loop. Any help would be appreciated!