Please help with adding function of ranking every student's score

Hello
I just started working with dev c++ and computer languages at all because of my course
Now, could you please help with adding a function of ranking every student's score?
I already did average, total and now I just need it to show which rank belongs to each student. It doesn't have to be in ascending or descending order, instead simply showing which rank is whose based on the total value.

#include <windows.h>
#include <tchar.h>
#include <stdio.h>

#define ID_MENU_OPEN 1
#define ID_MENU_SAVE 2
#define ID_MENU_EXIT 3
#define ID_MENU_SAVE_AS 4
#define ID_MENU_MOVE 11
#define ID_MENU_SAVE_RESULT 12
#define ID_MENU_PLUS_ONE 13
#define ID_MENU_MAX_VALUE 14
#define ID_MENU_MAKE_RANDOM_DATA 15
#define ID_MENU_REVERSE_DATA 16
#define ID_MENU_CHANGE_BASE 17
#define ID_MENU_DETERMINE_PRIME 18
#define ID_MENU_FIND_PRIME 19

#define ID_SCO_MENU_SCORE_CALCU 21
#define ID_SCO_MENU_SCORE_CALCU_WITH_NAME 22

#define TEXT_LENGTH 200
#define BUFF_SIZE 3000
#define WHITE_SPACE 10
#define MAX_DATA_NUM 200
#define MAX_PRIME_NUM 3000
#define MAX_STRING_LENGTH 200

#define MAX_STUDENT_NUM 60

typedef struct{
int number;
TCHAR name[10];
int kor;
int math;
int eng;
int tot;
float avg;
}STUDENT_SCORE;

void scoreCalculator(HWND hwnd, HWND hSrc, HWND hDst){
TCHAR buff[BUFF_SIZE];
DWORD fileSize;
char* tok;
int MAX_COL_NUM = 5;
int NUMPOS=0, KORPOS=1, MATHPOS=2, ENGPOS=3, TOTPOS=4;
int stdScore[MAX_STUDENT_NUM][MAX_COL_NUM], stdNum;

fileSize = GetWindowText(hSrc, buff, BUFF_SIZE);
buff[fileSize+1] = NULL;
stdNum = 0;
tok = strtok(buff, "\r\n");
while(tok != NULL){
sscanf(tok,"%d %d %d %d\r\n",&stdScore[stdNum][NUMPOS],&stdScore[stdNum][KORPOS],
&stdScore[stdNum][MATHPOS],&stdScore[stdNum][ENGPOS]);
tok = strtok(NULL, "\r\n");
stdNum++;

if(stdNum >= MAX_PRIME_NUM){
MessageBox(hwnd, "The number of students is out of the storage range.", "Arrangement grade processing.", MB_OK);
return;
}
}

for(int i=0; i<stdNum; i++){
stdScore[i][TOTPOS] = stdScore[i][KORPOS]+stdScore[i][MATHPOS]+stdScore[i][ENGPOS];
}

TCHAR str[MAX_DATA_NUM];
sprintf(buff,"%-s\t%-s\t%-s\t%-s\t%-s\t\r\n","Number","Kor","Math","Eng", "Total");
for(int i=0; i<stdNum; i++){
sprintf(str,"%-d\t%-d\t%-d\t%-d\t%-d\t\r\n", stdScore[i][NUMPOS],stdScore[i][KORPOS],
stdScore[i][MATHPOS],stdScore[i][ENGPOS],stdScore[i][TOTPOS]);
strcat(buff,str);
}

strcat(buff,"\r\n");
SetWindowText(hDst, buff);

}

void scoreCalculatorWithName(HWND hwnd, HWND hSrc, HWND hDst){
TCHAR buff[BUFF_SIZE];
DWORD fileSize;
char *tok;
int stdNum;
STUDENT_SCORE stdScore[MAX_STUDENT_NUM];

fileSize = GetWindowText(hSrc, buff, BUFF_SIZE);
buff[fileSize+1] = NULL;
stdNum = 0;
tok = strtok(buff, "\r\n");
while(tok != NULL){
sscanf(tok,"%d %s %d %d %d\r\n", &stdScore[stdNum].number,&stdScore[stdNum].name,
&stdScore[stdNum].kor,&stdScore[stdNum].math,
&stdScore[stdNum].eng,&stdScore[stdNum].rank);
tok = strtok(NULL, "\r\n");
stdNum++;
}

for(int i=0; i<stdNum; i++){
stdScore[i].tot = stdScore[i].kor+stdScore[i].math+stdScore[i].eng;
stdScore[i].avg = (float)stdScore[i].tot/3;
}

TCHAR str[MAX_DATA_NUM];
sprintf(buff,"%-s\t%-s\t%-s\t%-s\t%-s\t%-s\t%-s\r\n",
"Number","name","Kor","Math","Eng","Total","Average");
for(int i=0; i<stdNum; i++){
sprintf(str,"%-d\t%-s\t%-d\t%-d\t%-d\t%-d\t%-.1f\r\n",
stdScore[i].number, stdScore[i].name,
stdScore[i].kor, stdScore[i].math,stdScore[i].eng,
stdScore[i].tot, stdScore[i].avg);
strcat(buff,str);
}

strcat (buff,"\r\n");
SetWindowText(hDst, buff);

}

This is C, not C++.

You already have the student information in an array: stdScore.
Simply sort it on score.

PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.


Topic archived. No new replies allowed.