Code for Ranking please help

saintneo007

New Member
Good day!
[FONT=&quot]Hi everyone, kindly somebody help me with my program codes…I’m working on a tabulation program and I’m having a problem in ranking of candidates…my codes look like this:

DEFINE VARIABLE rankme as decimal NO-UNDO.
FOR EACH contestant WHERE contestant.catcode = cb-category
AND contestant.judgenum = fi-judge
AND contestant.posted = YES EXCLUSIVE-LOCK BREAK BY
contestant.grade DESCENDING:
IF FIRST-OF(contestant.grade) THEN
DO:
ASSIGN rankme = rankme + 1
contestant.rank = rankme.
END.
END.

and the result like this...
c# - CName - Score - Rank
1 - Can A - 4.2 - 8.0
2 - Can B - 7.7 - 3.0
3 - Can C - 8.8 - 0.0
4 - Can D - 8.0 - 2.0
5 - Can E - 7.2 - 0.0
6 - Can F - 8.8 - 1.0
7 - Can G - 5.0 - 7.0
8 - Can H - 2.0 - 9.0
9 - Can I - 6.6 - 6.0
10 - Can J - 7.0 - 5.0
11 - Can K - 7.2 - 4.0

my question is how can i make my raking result give like this...

c# - CName - Score - Rank
1 - Can A - 4.2 - 10.0
2 - Can B - 7.7 - 4.0
3 - Can C - 8.8 - 1.5
4 - Can D - 8.0 - 3.0
5 - Can E - 7.2 - 5.5
6 - Can F - 8.8 - 1.5
7 - Can G - 5.0 - 9.0
8 - Can H - 2.0 - 11.0
9 - Can I - 6.6 - 8.0
10 - Can J - 7.0 - 7.0
11 - Can K - 7.2 - 5.5

hope you figure out the rank with ".5" or giving same rank ...sequence of rank added and divided in numbers of contestant having the same score...kindly help...thanks and God bless.
[/FONT]
 
I would suggest that you don't really want to make it 1.5 ... what, for example, would you do if there were three people all tied for first? And, of course, that is the convention ... "Tied for Nth".

So, all you have to do is to add two variables -- the last rank assigned and the last score. As you read each record, compare the current score to the prior score. If it is the same, return the prior rank instead of the current one. If it is lower, then return the current rank and update the prior score and rank. This will give you 1, 1, 3, etc.
 
thanks sir...i much appreciated it but can you give me a sample code for it...because putting ELSE will give me a result like this 1, 1, 2, 3, 4, 5, 5, ...ect. code goes like this:

[FONT=&quot] DEFINE VARIABLE rankme as decimal NO-UNDO.
FOR EACH contestant WHERE contestant.catcode = cb-category
AND contestant.judgenum = fi-judge
AND contestant.posted = YES EXCLUSIVE-LOCK BREAK BY
contestant.grade DESCENDING:
IF FIRST-OF(contestant.grade) THEN
DO:
ASSIGN rankme = rankme + 1
contestant.rank = rankme.
END.
ELSE
[/FONT][FONT=&quot]contestant.rank = rankme. [/FONT]
[FONT=&quot] END.[/FONT]
 
Obviously one doesn't do it that way. Like I said, you need two additional variables. The one you call rankme is incremented every time. But, if the score is the same as the prior person's score, then you assign the saved rank instead. It's good exercise to work out the code yourself...
 
Obviously one doesn't do it that way. Like I said, you need two additional variables. The one you call rankme is incremented every time. But, if the score is the same as the prior person's score, then you assign the saved rank instead. It's good exercise to work out the code yourself...

Thank you. I've already solve the code after having good exercise of my logic skills...thank's and God bless.
 
Back
Top