簡體   English   中英

cs50 - 問題集 3 多個代碼無法編譯

[英]cs50 - problem set 3 plurality- code failed to compile

我制作的代碼是針對 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]);
    
}

你能幫我解決這個錯誤嗎?

規范

除了vote 和print_winner 函數的實現(以及包含額外的頭文件,如果您願意)之外,您不應修改multiple.c 中的任何其他內容。

最好從發行版代碼開始。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM