[英]cs50 - problem set 3 plurality- code failed to compile
The code I made is for cs50 problem set 3 plurality.我制作的代码是针对 cs50 问题集 3 的。 When I run the code myself, the code works as expected.当我自己运行代码时,代码按预期工作。 However when I run check50, I get the error "code failed to compile".但是,当我运行 check50 时,出现错误“代码无法编译”。 When I run check50 i get this error:当我运行 check50 时,我收到此错误:
:) plurality.c exists
:( plurality compiles
code failed to compile
:| vote returns true when given name of first candidate
can't check until a frown turns upside down
:| vote returns true when given name of middle candidate
can't check until a frown turns upside down
This is my code:这是我的代码:
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <cs50.h>
#include <stdbool.h>
#include <string.h>
int main(int argc, string argv[])
{
if(argc<2)
{
return 1;
}
int cand_count = argc-1;
if ((cand_count)>9)
{
return 1;
}
int scores[]={0,0,0,0,0,0,0,0,0};
int voters_count=get_int("Number of voters: ");
for (int a=0; a<voters_count; a++)
{
string question =get_string("vote: ");
for (int b=0; b<cand_count; b++)
{
if (strcmp( question, argv[b+1]) == 0 )
{
scores[b]=(scores[b]+1);
}
}
}
int highest=0;
int position=0;
for (int d=0; d<9; d++)
{
if ((scores[d])>(highest))
{
highest=scores[d];
position=d;
}
}
printf("%s",argv[position+1]);
}
Can you please help me fix this error.你能帮我解决这个错误吗?
You should not modify anything else in plurality.c other than the implementations of the vote and print_winner functions (and the inclusion of additional header files, if you'd like).除了vote 和print_winner 函数的实现(以及包含额外的头文件,如果您愿意)之外,您不应修改multiple.c 中的任何其他内容。
Best to start with the distro code .最好从发行版代码开始。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.