L
L
Learpcs2017-12-17 22:14:20
Pascal
Learpcs, 2017-12-17 22:14:20

Why doesn't a compiled pascal program run without a shell?

I'm teaching my friend Pascal, and he wants his application to work separately from the shell.
I did everything I needed and set saving the exe file to a separate folder I
run the file, it loops and after that the program ends, although there are a couple more lines of code
However, if you run it through the shell, the program works properly
I can’t understand what the problem is!

var otvet,ans,attempts:integer;
begin
otvet:=random(100);
writeln('Привет,это игра "Угадай число",правила просты.');
writeln('Отгадай число загаданное,мной,ВЕЛИЧАЙШЕЙ В МИРЕ ПЕКАРНЕЙ ВСЕЯ РУСИ.');
readln(ans);
while(ans <> otvet) do 
  begin
    attempts:=attempts+1;
    if(ans < otvet) then begin writeln('Мое число больше!'); ans := otvet; readln(ans); end
    else if(ans > otvet) then begin writeln('Мое число меньше!'); ans := otvet; readln(ans); end
  end;
writeln('Молодец, ты меня победил!');
writeln('Твое количество попыток: '+ attempts);
end.

PS Game guess the number

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Mirilaczvili, 2017-12-18
@Learpcs

The output to the screen is made in a text window (console mode), while the last text just skips a glimpse, the program ends and the text window closes immediately.
Therefore, you need to run the executable either using cmd.exe, or in a Pascal program by adding the last line ReadLn;, re-compiling it into an executable. In the latter case, the program will wait for Enter to be pressed.

K
KKINIUSS, 2018-02-26
@KKINIUSS

I think after writeln('Your number of attempts: '+ attempts); you need to write "readkey;" so that the answer is delayed until the key is pressed) unsubscribe if the verb is correct))))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question