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

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.

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,PosNumebrCou

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.

Experts Exchange Solution brought to you by

Enjoy your complimentary solution view.

Get this solution by purchasing an Individual license!
Start your 7-day free trial.

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.

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

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

var

number,PosSum,PosNumebrCou

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.

var

number,PosSum,PosNumebrCou

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.

There were 1 negative values, average -8.0"

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 trialWhat numbers do you have for the Positive values? For the Negative values?

mlmcc

mlmcc

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

Look forward to helping you in the future

mlmcc

Pascal

From novice to tech pro — start learning today.

Experts Exchange Solution brought to you by

Enjoy your complimentary solution view.

Get this solution by purchasing an Individual license!
Start your 7-day free trial.