1

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

user1704677
  • 101
  • 1
  • 2
  • 12

1 Answers1

4

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?

Simon Wright
  • 25,108
  • 2
  • 35
  • 62
  • ah, thank you so much. And I'm assuming it starts initialized as 0, is that incorrect? – user1704677 Oct 16 '12 at 22:03
  • @user1704677: Yes, that's incorrect. It will be initialized to some garbage value. Why do you assume it's initialized to 0? – Keith Thompson Oct 16 '12 at 23:26
  • 1
    @user1704677: Keith Thompson's question is particularly cogent, as you have [previously used Java](http://stackoverflow.com/q/12906061/230513) where that behavior is [defined](http://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html#jls-4.12.5). Note that in Ada, ["There is no implicit initial value defined for a scalar subtype."](http://www.adaic.org/resources/add_content/standards/05rm/html/RM-3-3-1.html) – trashgod Oct 17 '12 at 00:46
  • Right, I'm a Java guy so that's why I assumed that it was initialized to zero. Thanks for that tip. – user1704677 Oct 17 '12 at 01:49
  • Quite. Note that Ada (perhaps unlike Java) allows integer types where 0 is an invalid value. If it then initialized everything to zero, people with such Integer types would get all sorts of inexplicable constraint errors. Not to mention that it would often be a waste of CPU (every time you were going to write to it before reading anyway). – T.E.D. Oct 17 '12 at 14:11