print_winner 函数必须找到得票最高的候选人并打印其名字。如果有两名候选人拥有相同的票数,该函数必须打印 2 个名字。
这里有错误
:( print_winner identifies Alice as winner of election
print_winner function did not print winner of election
:( print_winner identifies Bob as winner of election
print_winner function did not print winner of election
:( print_winner identifies Charlie as winner of election
print_winner function did not print winner of election
:( print_winner prints multiple winners in case of tie
print_winner function did not print both winners of election
:( print_winner prints all names when all candidates are tied
print_winner function did not print all three winners of election
这是我的功能代码
void print_winner(void)
{
int maxx;
maxx = candidates[0].votes;
for (int i = 1; i < candidate_count; i++)
{
if(maxx < candidates[i].votes)
{
maxx = candidates[i].votes;
}
}
for (int j = 0; j < candidate_count; j++)
{
if (candidates[j].votes == maxx)
{
printf("%s \n", candidates[j].name);
}
}
}
来自规格
该函数应打印出在选举中获得最多选票的候选人的姓名,然后打印换行符。
此
printf("%s \n", candidates[j].name);
打印候选人的姓名,一个空格,然后是换行符。这看起来似乎是一个微不足道的差异,实际上人眼无法察觉,但 check50 没有找到与预期输出完全匹配的结果。