Multiple Same highest score

I'm trying to add figure out how to put multiple names with the same highest score on the same test with the first and last name.

let's say

Mark Anderson 100%
Susan Barlow 87%
Tom Brown 100%
Maggie Change 99%
Maureen Ferguson 100%

The end result shows that Mark Anderson scored the highest, but it is clear that Tom Brown and Maureen Ferguson are also the highest


This is part of my code.

int find_highest_pos(vector<int>& test)
{
int max_pos=0;
for(int i=0; i<test.size(); i++)
{
if(test[max_pos]<test[i])
max_pos=i;
}
return max_pos;
}

fout<<"Test "<<1<<" highest: "<<setw(15)<<last[highest_pos[0]]<<setw(15)<<first[highest_pos[0]]<<setw(15)<<test1[highest_pos[0]]<<endl;
Then you should return a list of numbers from function rather than a single number
how would i do that?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
list<int> find_highest_pos(vector<int>& test)
{
    int max=0;
    list<int> max_positions;
    for(int i=0; i<test.size(); i++)
    {
        if(max<test[i])
            max=test[i];
    }
    for(int i=0;i<test.size();++i)
    {
        if(test[i]==max)
            max_positions.push_back(i);
    }
    return max_positions;
}
@while, it can be done with one loop, but your method is clearer

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <limits>

list<int> find_highest_pos(vector<int>& test) {
    int max = std::numeric_limits<int>::min();
    list<int> max_positions;
    for(int i = 0; i < test.size(); i++) {
        if(max < test[i]) {
            max_positions.clear()
            max_positions.push_back(i);
            max = test[i];
        }
        else if (max == test[i]) {
            max_positions.push_back(i);
        }
    }
    return max_positions;
}
it it possible to only use vectors?
Topic archived. No new replies allowed.