• 1000 в случае at ie (и я тестировал его несколько раз для различных сценариев ios) эта ошибка все еще сохраняется, и я не уверен, почему. Может ли кто-нибудь изучить мой код ниже и уточнить, что с ним не так? (Прошу прощения, если это очень беспорядочно / неэффективно - мне потребовалось время, чтобы написать его, потому что мне потребовалось время, чтобы выяснить, как распечатать несколько победителей):
void print_winner(void)
{
int j = 0;
int max = candidates[0].votes;
int competitor;
int competitor2;
string winner = candidates[0].name;
// loop over all candidates + determine candidate with most votes (max)
// + name candidate with most votes (winner)
for (j = 1; j < candidate_count; j++)
{
competitor = candidates[j].votes;
if (max < competitor)
{
max = competitor;
winner = candidates[j].name;
}
}
// loop over candidates again to determine if multiple winners + print winner/winners
for (int f = 0; f < candidate_count; f++)
{
competitor2 = candidates[f].votes;
if (max == competitor2 && candidates[f].name != winner)
{
for (int i = 0; i < candidate_count; i++)
{
printf("%s\n", candidates[i].name);
}
return;
}
}
printf("%s\n", winner);
return;
}
EDIT : Как указал DinoCoderSaurus, мой i
l oop был проблематичным c. Я понял, что это даже не нужно, так как мой f
l oop уже выполняет ту же функцию. Ниже я удалил i
l oop, немного изменил f
l oop и переместил строку printf("%s\n", winner);
перед f
l oop, поэтому, если есть несколько победителей, они печатаются в правильном порядке:
void print_winner(void)
{
int j = 0;
int max = candidates[0].votes;
int competitor;
int competitor2;
string winner = candidates[0].name;
// loop over all candidates + determine candidate with most votes (max)
// + name candidate with most votes (winner)
for (j = 1; j < candidate_count; j++)
{
competitor = candidates[j].votes;
if (max < competitor)
{
max = competitor;
winner = candidates[j].name;
}
}
printf("%s\n", winner);
// loop over candidates again to determine if multiple winners + print winner/winners
for (int f = 0; f < candidate_count; f++)
{
competitor2 = candidates[f].votes;
if (max == competitor2 && candidates[f].name != winner)
{
printf("%s\n", candidates[f].name);
}
}
return;
}