Shooting competition

Hello people! I need help with an exam task that I can not handle ... I'm new to programming and I have no idea how to do it. I'll be grateful for your help! Here's her task:
Console application (without input from the console - possibly with arrays with fixed application data). At a shooting competition that takes place once a year, there are up to 30 contestants. For each individual competition, a stand-alone list of participants information is made. Each athlete is described with the name, PIN and points he receives (eg Ivan Ivanov - 1234567890 - 60). Competition data was entered in 2015, 2016, and 2017. Provide information - for the competition with the highest total number of points and the competition with the lowest total number of points. - the competitor (s) with the highest total points for all years.

Last edited on
> the race with the highest total number of points
¿race?

> the competitor (s) with the highest total points for all years.
¿for each year or you make a weighted average?
Sorry! Broken English... The same competitors for all years. For example, John Dow with maximum points for 2015 + 2016 + 2017.

#include <iostream>
#include <string>
#include <conio.h>
#include <map>
#include <list>

using namespace std;

struct person
{
string name;
double egn;
int points;
};

int main()
{
map<int, list<person>> competitions;
map<double, int> persons;
map<double, string> nameByEgn;

competitions[2015] = { { "John", 8505234344, 20 }, { "Mark", 8505234345, 20 } };
competitions[2016] = { { "John", 8505234344, 19 }, { "Mark", 8505234345, 17 }, { "Mery", 8505234346, 17 } };
competitions[2017] = { { "John", 8505234344, 25 }, { "Mark", 8505234345, 30 } };

int min = INT32_MAX;
int max = INT32_MIN;
string min_year;
string max_year;

for (map<int, list<person>>::iterator competitionIt = competitions.begin(); competitionIt != competitions.end(); ++competitionIt)
{
int sum = 0;
for (list<person>::iterator personIt = competitionIt->second.begin(); personIt != competitionIt->second.end(); ++personIt)
{
sum += personIt->points;
if (persons.find(personIt->egn) == persons.end())
{
persons[personIt->egn] = 0;
}
persons[personIt->egn] += personIt->points;
if (nameByEgn.find(personIt->egn) == nameByEgn.end())
{
nameByEgn[personIt->egn] = personIt->name;
}
else if (nameByEgn[personIt->egn] != personIt->name)
{
cout.precision(0);
cout << "Error: " << nameByEgn[personIt->egn] << " and " << personIt->name << " are with same id=" << fixed << personIt->egn << endl;
_getch();
return 1;
}
}
if (sum < min)
{
min = sum;
min_year = to_string(competitionIt->first);
}
else if (sum == min)
{
min_year += ", ";
min_year += to_string(competitionIt->first);
}
if (sum > max)
{
max = sum;
max_year = to_string(competitionIt->first);
}
else if (sum == max)
{
max_year += ", ";
max_year += to_string(competitionIt->first);
}
}
cout << "Max points: " << max << " year " << max_year << endl;
cout << "Min points: " << min << " year " << min_year << endl;

int max_points = INT32_MIN;
double max_egn;
for (map<double, int>::iterator it = persons.begin(); it != persons.end(); ++it)
{
if (max_points < it->second)
{
max_points = it->second;
max_egn = it->first;
}
}
cout.precision(0);
cout << nameByEgn[max_egn] << " with id=" << fixed << max_egn << " has max points: " << max_points;

_getch();
return 0;
}

What is wrong in this code???
Last edited on
Can anyone tell me?
> What is wrong in this code?
¿why are you asking? ¿does it solve your problem?
the code is quite convoluted and doesn't have a single comment, not going to analyse it.
so I thought it would make a decision on my assignment, but I'm mistaken... I would not want help here if I knew how to solve my problem myself...
Why don't you ask the one who gave you that code yesterday?
http://forums.bgdev.org/index.php?showtopic=49844&st=10
I understood what is wrong - just my IDE is not ok...
Topic archived. No new replies allowed.