1

私が取り組んでいるこの Ada プログラムをコンパイルしようとすると、なぜ未定義のエラーが発生するのか完全に困惑しています。私はそれを何度も見直しました... スペルミスやその性質のものはありません。これが私が持っているもので、続いて私が得ているエラーがあります。

Get_Score(CandidateVotes, CurrentCandidate);
                end loop;
        end Get_Input;

procedure Get_Score(CandVotes: in CurrentCandidate_Votes; 
            Candidate: in Character) is
-- get the score for the candidate and store it into CandidatesArray
            SameAnswers: Integer;
            DifferentAnswers: Integer;
            CandidateScore: Integer;
    begin
            for I in VoterArray_Index loop
                    if Voter(I) /= 0 And CandVotes(I) /= 0 Then
                            if Voter(I) /= CandVotes(I) Then
                                    DifferentAnswers := DifferentAnswers + 1;
                            else
                                    SameAnswers := SameAnswers + 1;
                            end if;
                    end if;
            end loop;
            CandidateScore := SameAnswers - DifferentAnswers;
            Candidates(Candidate) := CandidateScore;

    end Get_Score;

コード ブロックの上部は、別のプロシージャから Get_Score プロシージャを呼び出している場所です。CandidateVotes と CurrentCandidate のタイプは正しいです。もっと投稿する必要がある場合は、お知らせください。

また、エラーには次のように表示されます。

4

1 に答える 1

4

Get_Score使用する前に定義する必要があります。

怠惰な方法は、サブプログラム本体が適切な順序になるようにコードの順序を変更することです。

Ada のやり方は、最初にサブプログラムの仕様を (好きな順序で) 書き、次に本体を好きな順序で実装することです。

のスペックGet_Score

procedure Get_Score(CandVotes: in CurrentCandidate_Votes; 
                    Candidate: in Character);

ちなみに書くときは

DifferentAnswers: Integer;

DifferentAnswersどのような値で始まると思いますか?

于 2012-10-16T21:33:57.510 に答える