【问题标题】:cs50 - problem set 3 plurality- code failed to compilecs50 - 问题集 3 多个 - 代码编译失败
【发布时间】:2021-12-23 06:01:48
【问题描述】:

我编写的代码是针对 cs50 问题集 3 复数的。 当我自己运行代码时,代码按预期工作。但是,当我运行 check50 时,我收到错误“代码无法编译”。当我运行 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

这是我的代码:

#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]);
    
}

你能帮我解决这个错误吗?

【问题讨论】:

  • 该工具(我假设 check50 是您在本地运行的某种工具,请随时澄清)是否适用于其他问题?或者如果你只给它一个 hello world 程序,它会编译然后抱怨测试失败吗?

标签: c cs50


【解决方案1】:

来自the spec

除了 vote 和 print_winner 函数的实现(如果您愿意,还可以包含其他头文件)之外,您不应修改 multiple.c 中的任何其他内容。

最好从distro code开始。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-04
    • 2011-01-22
    • 1970-01-01
    • 2022-01-21
    • 2022-12-11
    • 2013-09-02
    相关资源
    最近更新 更多