Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2007-10

readln problem

4 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Petr Katovsky

Hello, i would like to use the Readln command to wait for the user to press enter before ending the program.

1.First example - it works fine:

program hello;
    begin
      writeln('Hello world');
      readln;
    end.

2.Second example - it does not work.

program NUMBERS (Input,Output);
var A,B : Integer;
begin
        Write ('Find greater number.');
        Write ('Enter two numbers.');
        Read (A,B);
        if A>B then
                Write ('The greater number is',A)
                else
                Write ('The greater number is',B);
                readln;
end.

Could anybody tell me why it does not work?
Thanks a lot

Reply by email

Petr Katovsky
to L: Alternatively: program NUMBERS (Input,Output); var A,B : Integer; begin Write ('Find…

Yes, it's working fine.
Thank you a lot.

Earlier message 40 lines
-----Original Message----- From: On Behalf Of L Sent: Monday, October 29, 2007 3:49 PM To: f dvl list Subject: Re: [fpc-devel] readln problem > Something like this solves your problem > > program NUMBERS (Input,Output); > var A,B : Integer; > begin > Write ('Find greater number.'); > Write ('Enter two numbers.'); > Read (A,B); > if A>B then Write ('The greater number is ',A) > else > Write ('The greater number is ',B); > readln; > readln; > end. Alternatively: program NUMBERS (Input,Output); var A,B : Integer; begin Write ('Find greater number.'); Write ('Enter two numbers.'); Read (A,B); readln; if A>B then Write ('The greater number is ',A) else Write ('The greater number is ',B); readln; end.

Reply by email

L
to Petr Katovsky: Hello, i would like to use the Readln command to wait for the user to press enter before…
Show quoted text 19 lines
2.Second example - it does not work. program NUMBERS (Input,Output); var A,B : Integer; begin Write ('Find greater number.'); Write ('Enter two numbers.'); Read (A,B); if A>B then Write ('The greater number is',A) else Write ('The greater number is',B); readln; end. Could anybody tell me why it does not work? Thanks a lot

This should probably be on the fpc-pascal mailing list rather than devel.

Something like this solves your problem

program NUMBERS (Input,Output);
var A,B : Integer;
begin
  Write ('Find greater number.');
  Write ('Enter two numbers.');
  Read (A,B);
  if A>B then Write ('The greater number is ',A)
  else
    Write ('The greater number is ',B);
  readln;
  readln;
end.

Because you must hit enter twice.. once after the first read, then once to end the program.

Reply by email

L
Show quoted text 14 lines
Something like this solves your problem program NUMBERS (Input,Output); var A,B : Integer; begin Write ('Find greater number.'); Write ('Enter two numbers.'); Read (A,B); if A>B then Write ('The greater number is ',A) else Write ('The greater number is ',B); readln; readln; end.

Alternatively:

program NUMBERS (Input,Output);
var A,B : Integer;
begin
  Write ('Find greater number.');
  Write ('Enter two numbers.');
  Read (A,B);
  readln;
  if A>B then Write ('The greater number is ',A)
  else
    Write ('The greater number is ',B);
  readln;
end.

Reply by email