CS50 Plurality问题:修改main后代码仍未通过check50求助
CS50选举作业:print_winner函数用全局voter_count过不了check50的问题
我在写CS50的选举作业时,觉得在print_winner函数里用上main里的voter_count变量会很实用,但这个变量不像candidate_count那样在main函数之前就有声明,没法直接在print_winner里访问。
于是我在main函数之前加了全局变量声明:
//Number of votes int voter_count;
同时把main里的这行代码:
int voter_count = get_int("Number of voters: ");
改成了:
voter_count = get_int("Number of voters: ");
自己测试所有场景代码都能正常运行,但我明知道不该修改main函数,而且就算改了,代码还是过不了check50。有人知道这是为什么吗?
我的print_winner函数代码如下:
void print_winner(void) { for (int c = voter_count; (c > 0); c--) { int u = 0; for (int j = 0; (j < candidate_count); j++) { if (candidates[j].votes == c) { u++; printf("%s \n", candidates[j].name); } } if (u != 0) { return; } } }
内容的提问来源于stack exchange,提问作者Cas
相关产品推荐
相关产品推荐

