954,541 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Problem with for loop (i think)

Using Borland Pascal- Making a program to read in names and sales figures from text file and then (amongst other things) find the average of the sales and compare all the sales figures to the average. The problem is, only the last entry in the text file comes out for the average comparison. All other aspects of the program work fine. I believe the problem is in this procedure (the rest of the program can be provided on request, it's kinda long):

Procedure comparison;
begin
For index:= 1 to max do;
begin
compare:=sales[index]-average;
Write (names[index],' ');
If compare>0 then
begin
textcolor (green);
Writeln ('£',compare:4:2);
end
else
begin
textcolor (red);
Writeln ('£',compare:4:2);
end;
readkey;
end;
textcolor (white);
end;

WarKirby
Newbie Poster
1 post since Mar 2006
Reputation Points: 10
Solved Threads: 0
 

Hi, I dont see the problem here.
I would suggest check the followin:
Is max set to the size of sales ?
Does sales contain more the 1 entry ?
What does the readkey procedure do ?
(I code in Dephi so i have to get accustomed to pascal syntax).

frunnik
Newbie Poster
3 posts since Mar 2006
Reputation Points: 10
Solved Threads: 0
 

Hi,

Simply remove the ; on the line For index:= 1 to max do;

Loren Soth

Lord Soth
Posting Whiz in Training
233 posts since Mar 2006
Reputation Points: 28
Solved Threads: 4
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You