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

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');
readln(stop);
while stop <> 0 do
begin
posinteger := stop mod 2;
readln;
if posinteger = 0
then
writeln('This number is even')
else

writeln('This number is odd');
readln;
clrscr;
writeln('Enter a positibe integer, 0 to quit');
readln(stop);
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');
  readln(stop);
  while stop <> 0 do
    begin
    posinteger := stop mod 2;
    readln;
    if posinteger = 0
      then writeln('This number is even')
      else writeln('This number is odd');

    sum := sum + stop;

    writeln( 'Press ENTER to continue' );
    readln;

    clrscr;
    writeln('Enter a positive integer, 0 to quit');
    readln(stop);
    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! :)

program eight;
uses crt;

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

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

    sum := sum + stop;

    writeln( 'Press ENTER to continue' );
    readln;

    clrscr;
    writeln('Enter a positive integer, 0 to quit');
    readln(stop);
    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!

This article has been dead for over six months. Start a new discussion instead.