hey there, does anyone know a way that will allow the user to enter as many positive integers as they want, for each one i need a message to appear that states whether the number is odd or even?

cheers guys

## All 6 Replies

Sounds like you are asked to do something repetitively, so that suggests using a loop. Post some code and we'll help further. (You should be able to do this on your own.)

``````program eight;
uses crt;

var
stop : integer;
posinteger : integer;
sum : integer;

begin
sum := 0;
writeln('Enter a positive integer, 0 to quit');
while stop <> 0 do
begin
posinteger := stop mod 2;
if posinteger = 0
then
writeln('This number is even')
else

writeln('This number is odd');
clrscr;
writeln('Enter a positibe integer, 0 to quit');
end;
end.``````

done it! :P

Brilliant.

I'm going to pick. The way your code looks is a tremendous help to understanding.

``````program eight;
uses crt;

var
stop       : integer;
posinteger : integer;
sum        : integer;

begin
sum := 0;
writeln('Enter a positive integer, 0 to quit');
while stop <> 0 do
begin
posinteger := stop mod 2;
if posinteger = 0
then writeln('This number is even')
else writeln('This number is odd');

sum := sum + stop;

writeln( 'Press ENTER to continue' );

clrscr;
writeln('Enter a positive integer, 0 to quit');
end;

writeln( 'The sum of all the numbers you entered is ', sum );
end.``````

You'll notice I made a couple of minor changes. First, I told the user (who might not be you) what he is expected to do to continue when the program pauses. Also, you had defined a variable "sum" which didn't do anything. I made it do something.

Enjoy! :)

that rocks! thanks! :D!

``````program eight;
uses crt;

var
stop       : integer;
posinteger : integer;
sum        : integer;

begin
sum := 0;
writeln('Enter a positive integer, 0 to quit');
while stop <> 0 do
begin
posinteger := stop mod 2;
if posinteger = 0
then writeln('This number is even')
else writeln('This number is odd');

sum := sum + stop;

writeln( 'Press ENTER to continue' );

clrscr;
writeln('Enter a positive integer, 0 to quit');
end;

writeln( 'The sum of all the numbers you entered is ', sum );
end.``````

Duoas, I think that the readln in the line 16 must be put at line 20 in order to display messages in the lines 18 ou 19 and pause execution, like You put on others code place.

bye

Yes, I totally missed that one. I wouldn't just move it, I'd get rid of it completely. The user shouldn't have to press ENTER more than once per answer, and only when asked...

Good eye!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.