Solved

# PASCAL Array problem / question

Posted on 2008-10-29

Hi there!

I'm very new to pascal, and currently have a issue with array programming... I need to make a tool for a teacher where he can add all testscores into a array, and calculate how many people have scores lower then 5, higher then 5, and whats the avarage score. This is not a homework assignment btw, I'm just trying to learn and understand how to fix problems with array solutions.

I made this code now but something is not good and i cant get a hold of it... Are there any PASCAL gurus out here who can give me a bit of help? :)

So the table sort of needs to look like this and i need to do some calculations based on the indexes:

Points: 1 2 3 4 5 6 7 8 9 10

Frequency: 0 1 4 5 6 9 3 2 1 1

I was able to come up with the following code but its still wrong.. What am i doing wrong here?

Var freq: Array[1..10,0..1] of integer;

GoodScore, BadScore, FreqTot, Points, Total : Integer;

Avarage : Real;

begin

try

BadScore := 0;

while Points <= 10 do

begin

for Points := 1 to 10 do;

for FreqTot := 0 to 1 do;

Freq[Points,FreqTot] := 0;

Points := 1;

FreqTot := 0;

while Points <= 10 do

Write ('give Points: ');

Readln (Points);

Total := Total + Points * Freq[Points];

if Points <= 5

then BadScore := BadScore + Freq[Points];

Points = Points + 1;

end;

Avarage := Total / FreqTot;

GoodScore := 0;

Points = 10;

While Points > Avarage do

begin

GoodScore := GoodScore + Freq[Points];

Points := Points -1;

end;

Write (GoodScore) (Avarage) (BadScore);

Readln;

except

on E:Exception do

Writeln(E.Classname, ': ', E.Message);

end;

end.