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
         readln(numbers[i]);
         total:=total+numbers[i];
         average:=total/10;
         difference:=numbers[i]-average;
         End;

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


End.

Please please could someone, anyone help me?!?!
Thanks.
LVL 1
emmarichardsonAsked:
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.

emmarichardsonAuthor Commented:
Adjusted points to 100
0
HypoCommented:
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
  readln(Number);
  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);
  readkey;
  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;
  readkey;
 end;
end.
0
emmarichardsonAuthor 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
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

HypoCommented:
Well, you can replace all Readkey with Readln without a problem.

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

Your issues matter to us.

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

Start your 7-day free trial
emmarichardsonAuthor Commented:
Thanks, but what does the  (for example) 6 represent ?  (Numbers[i]:6,)
0
HypoCommented:
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
emmarichardsonAuthor Commented:
Thanks for your help!
0
emmarichardsonAuthor Commented:
I've just tried out the program which you suggested and i have found that it does not work! At the last 'end' of the program it says its not complete! WHY?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Pascal

From novice to tech pro — start learning today.