Pregunta

I was trying to make a little test program to count how many times letter 'a' appears in an text without using string type:

program PascalTest;
uses WinCrt;
var 
 a:integer;
 ch:char;
begin
 a:=0;
 writeln('Input text: ');
 read(ch);
 while ch <>'.' do // '.' marking the end of text ("eoln" could've been used instead)//
  begin
   case ch of
   'A','a':a:=a+1;
   end;
   read(ch);
  end;
writeln(a);
readln;
readln; //forcing output window to stay open//
end. 

I noticed that if I dont add another 'readln' statement at the end , the output window will not show results (it will flash in an instant if u will).This is happening only with this program.All the other ones require only one 'readln' so the window can stay open. Can somebody explain to me why is another 'readln' statement needed in this case?

¿Fue útil?

Solución

The first readln ends the while loop. Note that you can enter many '.' without loop exit. Further note the writeln(a) is delayed until you press <Enter>. The second readln allows you to view the output.

Make a test: Uncomment both readln and see if you can end the program by entering a '.'.

Otros consejos

WinCrt is a consoleless CRT to use in combination with unit GRAPH.

Use unit Crt for normal console output.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top