# HELP!!!!!!!!!!!!!!Counting Var / Number

Hi,

I've been struggling with this for hours now.

It was set out as a boolean excercise but I've amended it a little by using procedures instead, this is minor as I shoudl jsut be able to revert it, I was trying to eliminate the global variables.

[code]
var numcheck:integer;
begin
writeln('What number/s would you like to check?');
posi:=0; negi:=0; zero:=0;

if numcheck>0 then writeln('This is a positive number');
if numcheck<0 then write('This is a negative number');
if numcheck=0 then write('This number is Zero');

end;

var count,totnum:integer;
begin
writeln('How many numbers will you like to check? ');

for count:= 1 to totnum do AskNumber //or 0 to totnum-1
end;

begin {main program}

writeln(posit,negit,zerot);
{up to 33750}
end.
[/code]

I need the program to decided whether a number is positive etc, this works fine. The part I'm stuck on is asking it to 'count' the number of pos/neg etc and to then display that number at the end.

The read line that i have is reading the number as an integer and not as a (+1) to be added. I've played arounfg with it so much but can't fget the fking thing to work.
Help!

• I've borrowed your code and made some alterations to get what I think you want.
[code][color=Green] var
posit,negit,zerot : integer;[/color]
var numcheck:integer;
begin
writeln('What number/s would you like to check?');
[color=Red](* posi:=0; negi:=0; zero:=0; *)[/color]
[color=Green]if numcheck>0 then begin
writeln('This is a positive number');
posit := posit + 1
[color=Green]if numcheck<0 then begin
write('This is a negative number');
negit := negit + 1
[color=Green]if numcheck=0 then begin
write('This number is Zero');
zerot := zerot + 1

end;

var count,totnum:integer;
begin
writeln('How many numbers will you like to check? ');

for count:= 1 to totnum do AskNumber //or 0 to totnum-1
end;

begin {main program}
[color=Green] posit := 0;
negit := 0;
zerot := 0;[/color]

writeln(posit,negit,zerot);
{up to 33750}
end.[/code]
• EDIT: Ignore post, seems Carl addressed these issues in the time I was away from my PC.

Haven't done Pascal in a few years so forgive my ignorance. First, is this line:

actually part of the if statement? To me it looks like it will be run whether the number is positive or not. Whether it is or isn't it looks like you're setting it to 0 each time, because of this line:

posi:=0; negi:=0; zero:=0;

As I said, I'm rusty so perhaps I'm wrong. Also, where are posit, zerot and negit declared, because if they are not global then (I believe) they will go out of scope each time you call the procedure and so it will not return any values to your main procedure.

Regards, Dai

------------------------------------------
Do or do not, there is no try. |
------------------------------------------