Finding Highest value

I need help finding the highest value in a vector and outputting the whole string.

I created a vector and all data successfully is entered and can be cout fine,
but I now need to sort the data in descending order and cout the line with the highest value(s)
Need help please.

Here is my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

#include <iostream>
#include <fstream>
#include <vector>

using namespace std;


struct Student
{
  int id;
  string name;
  int score;
};

int main()
{

  ifstream inStudentData("testdata.txt", ios::in);

  Student tempStudentObject;
  vector<Student> aVectorOfStudents;
  while (1)
  {

    if (!(inStudentData >> tempStudentObject.id)) break;
    inStudentData >> tempStudentObject.name;
    inStudentData >> tempStudentObject.score;
    aVectorOfStudents.push_back(tempStudentObject);
  }

   for (int i = 0; i< aVectorOfStudents.size(); ++i)
   {
       cout << i << " " << aVectorOfStudents[i].id << " "
              << aVectorOfStudents[i].name << " "
              << aVectorOfStudents[i].score << endl;
   }
}


[text]

2001 jaeery 89
2002 larry 09
2003 bunti 59
2004 james 89
2007 harases 44
2034 mark 73
2033 mathew 52
2048 mary 35
2045 eino 46
2042 rukoro 84
2043 ravid 83
2046 katji 82
2067 andrew 51
2021 andreas 83
2023 robert 45
2051 shipanga 85
2052 shikongo 35
2601 paulus 24
2701 david 43
2901 gariseb 55

[/text]


It is for a project that needs to be handed in the end of the week.
Last edited on
1. Those kind of tags don't work here. replace the <> with [] and get rid of <text> tags. You don't need them.
2. Indent your code
3. "Need help please" doesn't tell us much. Tell us what exactly is wrong with your program. If it's incorrect output, show us the output. If it's an error code, copy and paste the error code.
What is/are "the highest value(s)"? Shall you find all "the highest value(s)" or only the first?

Only the first, but in the text files case there are two identical ones.

So I need to output both strings in the following manner:

Student Number: 2001
First Name: Jaeery
Marks: 89

Paulthepenguin: The code is working fine thus far, but I'm stuck on coding to find the highest and lowest values.

I also need to sort the values in descending order and are also stuck on that part of the coding.
Topic archived. No new replies allowed.