Returning a struct

Hi guys the below are the codes I have written. i am trying to return a struct back to int main() so that i can display the topstudent in there after comparing the score of the students in struct markTable


#include <iostream>
#include <string>
#include <iomanip>
using namespace std;


markRec getTopStudent();
struct markRec
{
string studentpi, name;
double termtest, finalexam, score;
char grade;
};

struct markRec markTable[30]=
{
{"B001","Tan Choon Seng",34.0,67.0,53.8,'D'},
{"B002","Anne Smith", 79.0,88.2,83.6,'A'},
{"B003","Alice Lim", 56.0,45.0,49.4,'F'},
{"N003","Alan Phang", 67.0,87.0,79.0,'B'},
{"N005","Ho Tock Seng", 60.0,67.0,64.2,'C'},
{"N005","Tan Bee Hoon", 79.0,88.1,83.6,'A'},
};


int main()
{
}
markRec getTopStudent()
{
struct markRec temp[1];
for (int i=0; i < 30; ++i)
{
for (int j=i+1; j < 30; ++j)
{
if (markTable[i].score < markTable[j].score)
{
// exchange students

temp[i] = markTable[i];
markTable[i] = markTable[j];
markTable[j] = temp[i];
}
}
}
return temp[1];
}
And the problem is?
how do i return the struc in markRec getTopStudent() into int main()??
By calling the function from main.
I dunno how to do that u see..
i can know how to return a integer a double a boolean but i dunno how to return the struc.
To call a function in main:

1
2
3
4
5
int main()
{
     function_name (parameters);
}
you have to declare the struct before you declare any functions returning it.
when you declare markRec getTopStudent(); the compiler doesn't know what markrec is yet because you don't define it until the next line. just switch these around.
Topic archived. No new replies allowed.