user1704677
user1704677

Reputation: 111

Undefined Procedure in Ada

I'm completely stumped as to why I am getting an undefined error when I go to compile this Ada program I am working on. I have looked over it and over it... there are no spelling errors or anything of that nature. Here is what I have, followed by the error I am getting.

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;

The top part of the code block is where I am calling the Get_Score procedure from another procedure. The types of CandidateVotes and CurrentCandidate are correct. If I should post more, please let me know.

Also, the error reads: candidates.adb:37:25: "Get_Score" is undefined

Upvotes: 2

Views: 1926

Answers (1)

Simon Wright
Simon Wright

Reputation: 25511

You need to define Get_Score before you use it.

The lazy way is to re-order the code so that the subprogram bodies come in an appropriate order.

The Ada way is to write subprogram specs first (in whatever order you like), then implement the bodies, again in whatever order you like.

The spec of Get_Score is

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

By the way, when you write

DifferentAnswers: Integer;

what value do you think DifferentAnswers will start off with?

Upvotes: 3

Related Questions