Averages Program

I am having a bit of a problem completing this task and i was hoping someone could help me! I'm only using simple pascal language. Heres the question:

Design a program that accepts numbers (ending with -999 as a rogue value) and the prints out the average and also each number input. Beside each number is the difference from the average (obtained by subtracting the average from it).

So theres the question! And heres the program i have done so far...except its not very good and doesn't work yet!! Also i have to use an array with VERY SIMPLE LANGUAGE!!! Heres my program:

Program Averages;
Uses Crt;

VAR
numbers:array[1..100] of integer;
number,total,difference,i:integer;
average:real;

Procedure Main;
Begin
Clrscr;
writeln('Averages Program');
Total:=0;

For i:=1 to 10 {amount in list} do
Begin
total:=total+numbers[i];
average:=total/10;
difference:=numbers[i]-average;
End;

writeln('',number,' ',difference);
writeln('The Average is ',average);

End.

Thanks.
LVL 1
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Author Commented:
0
Commented:
Simple enough? Is this what you want?

Program Averages;

uses crt;

var Numbers : array[1..100] of integer;
Number  : integer;
Sum     : longint;
i,total : integer;
Average : real;

begin
clrscr;
writeln('Average program   Enter -999 to exit');
total := 0;
i := 1;
repeat
if Number <> -999 then begin
Numbers[i] := Number;
inc(Sum,Number);
inc(total);
inc(i);
end;
until (Number = -999) or (i > 100);

if total > 0 then begin
Average := Sum / total;
Writeln('Average is : ',Average :0:2);
For i := 1 to total do begin
writeln(Numbers[i]:6,' - ',Average:0:2,' = ',(Numbers[i]-Average):9:2);
if i mod 24 = 0 then readkey;
end;
end;
end.
0
Author Commented:
well, that program is ok, but the thing is that  i need to use simpler language.for example i don't use 'longint' or 'readkey'.
If you could leave these bits out and just stick to simple 'readln' etc.
0
Commented:

Longint can be replaced with integer... however, there might be an overflow so that the average value will not be correct. An Integer variable can hold any value from -32768..32767
Longint ,is a Long INTeger, wich can hold the values from -2147483648..2147483647,
So, as long as the total sum is less than 32767 you can use integer instead of longint without any problems.

you could also replace: writeln(Numbers[i]:6,' - ',Average:0:2,' = ',(Numbers[i]-Average):9:2); with
writeln(Numbers[i],' - ',Average,' = ',Numbers[i]-Average);
But If you do, the real values will be written as exponetial values, 1.00000000E+1 for instance.

This line can be removed :
If i mod 24 = 0 then readkey;

Other than that I don't know how to make the code any simplier...
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Author Commented:
Thanks, but what does the  (for example) 6 represent ?  (Numbers[i]:6,)
0
Commented:
Numbers[i]:6 makes the write or writeln procedure to make the size of the variable at least 6 digits.
e.g. if Numbers[i] = 123 it has 3 digits, but since we pass :6 after the variable, it'll be considered to have 6 characters by write/writeln nomatterwhat the actual size is.

So if
Writeln(Numbers[i],'!'); would give the output:
123!
Writeln(Numbers[i]:6,'!'); would give:
123   !

if you use :0:2 as we do when we write the average variable, :0 = the minimum number of characters in output, :2 = number of visible decimals in output!
0
Author Commented: