Pascal looping prgram

I need to write a Pascal program that keeps a few statistics on the programs' input.
The program needs to input real numbers from the keyboard, one at a time, until the
number typed in is zero.  At that time, I need it to show the final results.  During the input
process, it needs to track how many items are positive and how many are negative, and add the input
value to an appropriate running total.  When the loop is overwith, it needs to print the following:

There were 5 positive values, average 17.2
There were 2 negative values, average -8.7

If the number of positive or negative values is zero, don't compute or print the average.

Example run:

Type value: 17
Type value: -8
Type value: 21
Type value:  0

There were 2 positive values, average  19.0
There were 1 negative values, average  -8.0

This is what I have so far but its not working,

var
number,PosSum,PosNumebrCount,NegSum,NegNumebrCount: integer;
begin
 repeat
    write('Enter a number (0 to quit): '); readln(Number);
    { Calculations, see later }
  until Number = 0;


  if Number > 0 then
    begin
      PosSum := PosSum + Number;
      PosNumebrCount := PosNumebrCount + 1;
    end else if Number < 0 then begin
      { negative left to you }
    end;

  if Number < 0 then
  begin
      NegSum := NegSum + Number;

      NegNumebrCount := NegNumebrCount + 1;
      end else if Number < 0 then begin
      end;
end.

ffredsAsked:
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.

ffredsAuthor Commented:
Ok, I changed it to what I have so far. Bump
Mike McCrackenSenior ConsultantCommented:
Okay.  Thanks

Lets look at what your program does

1.  Read numbers until a 0 is read
2.  Test if positive
            Sum & count the positive numbers
3.  Test if negative
        Sum & count the negative numbers


What is wrong?  You read all the numbers then test them but the only number you have is 0

Try it more like this

1.  Read a number
2.  Test if positive
            Sum & count the positive numbers
3.  Test if negative
        Sum & count the negative numbers
4.  Repeat 1-3 until a 0 is read

What is left?
Calculate the averages
Display the summary

mlmcc

ffredsAuthor Commented:
Thats the problem though, I dont know HOW to get it to do that. This is as far as I can get and Im stuck, I have been working on it for hours and wasting my time I just dont get it.
Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

Mike McCrackenSenior ConsultantCommented:
here is what you have

Repeat
   Read numbers
Until 0

If positive
   Sum and count
If negative
   Sum and count

Try putting it like this

Repeat
   Read numbers
   If positive
      Sum and count
   If negative
      Sum and count
Until 0

How do you calculate an average?

How do you display the summary?

mlmcc
ffredsAuthor Commented:
I have

var
number,PosSum,PosNumebrCount,NegSum,NegNumebrCount: integer;
average: real;
begin
 repeat
    write('Enter a number (0 to quit): '); readln(Number);

  until Number = 0;


  if Number > 0 then
    begin
      PosSum := PosSum + Number;
      PosNumebrCount := PosNumebrCount + 1;
    end else if Number < 0 then begin

    end;

  if Number < 0 then
  begin
      NegSum := NegSum + Number;

      NegNumebrCount := NegNumebrCount + 1;
      end else if Number < 0 then begin
      end;

     until Number = 0;

  begin
   Sum=PosSum + NegSum

   Average := Sum / 2;

    WriteLn('The average is ', Average :7:5 );
    ReadLn;
  end;
end.
It gets a error at until number = 0 and I put it after the part where you said too.
Mike McCrackenSenior ConsultantCommented:
Remove the first one

mlmcc
ffredsAuthor Commented:
Ok I have...

var
number,PosSum,PosNumebrCount,NegSum,NegNumebrCount,Sum: integer;
Average: real;
begin
 repeat
    write('Enter a number (0 to quit): '); readln(Number);




  if Number > 0 then
    begin
      PosSum := PosSum + Number;
      PosNumebrCount := PosNumebrCount + 1;
    end else if Number < 0 then begin

    end;

  if Number < 0 then
  begin
      NegSum := NegSum + Number;

      NegNumebrCount := NegNumebrCount + 1;
      end else if Number < 0 then begin
      end;

      until Number = 0;

  begin
         Sum := PosSum + NegSum;
         Average := Sum / 2
         ****WriteLn****<'The average is ', Average :7:5 >;
    end;

end.

Everything goes fine until the WriteLn, it says it expects a ; but if I put that behind the 2 it gives 4 errors. It wont get past that.
Mike McCrackenSenior ConsultantCommented:
Why are you using the < >?  They should be ( )

mlmcc
ffredsAuthor Commented:
I just fixed it, nothing has changed though. I dont know why I did that
ffredsAuthor Commented:
Wow, I just got it to compile. But it didnt state the average or anything, it just closes
Mike McCrackenSenior ConsultantCommented:
Add the following before the END.

Write ("Enter a number to quit: ");
Readln (Number);

mlmcc
ffredsAuthor Commented:
Sorry for the post spamming, but I got it to say the average now. Now i just need to set it up where it does   "There were 2 positive values, average  19.0
There were 1 negative values, average  -8.0"
Mike McCrackenSenior ConsultantCommented:
You are calculating the averages here


  begin
         Sum := PosSum + NegSum;
         Average := Sum / 2
         ****WriteLn****<'The average is ', Average :7:5 >;
    end;



How do you calculate the Positive Average?

How do you calculate the Negative Average?

mlmcc

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
ffredsAuthor Commented:
I have no idea
Mike McCrackenSenior ConsultantCommented:
How do you calculate an average?

What numbers do you have for the Positive values?  For the Negative values?

mlmcc
ffredsAuthor Commented:
The numbers that are inputed, but how do i get those into the average code and how do I get it not to stop at after the Pos.
Mike McCrackenSenior ConsultantCommented:
An average is calculated by adding the values together and dividing by the number of values.  To find the Positive average do you have any variables with the appropriate values?

mlmcc
Mike McCrackenSenior ConsultantCommented:
I must signoff for now.  Will check this in the morning before I go to work

mlmcc
ffredsAuthor Commented:
I dont know what to do after that and the assigment is due in 20 minutes, hopefully I will get some credit for it.
ffredsAuthor Commented:
Do I still give you the points even though your a administrator?
Mike McCrackenSenior ConsultantCommented:
Your choice.  If the information was helpful then award the points.  

I have a dual role.  I am an expert first and also serve as the Page Editor.  Page editors try to ensure questions get answered but we must keep within the rules on the site.

As a hint.  Next time respond to comments much more quickly.  Don't wait for the last minute.

mlmcc

Mike McCrackenSenior ConsultantCommented:
Thank you.  On your next assignment if you need help give more information up front and don't wait for the last minute.

Look forward to helping you in the future

mlmcc
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.