Program closes right after the last input

Giovanni Solimeno

So I'm trying to write a program for school The problem is that even with a readln() the program closes right after the last output. This is the code, but I don't know what the problem is and I've tried everything;

program Calcolo;
var El, EC, S, N:Real;
var nome:string;
function returnVote(a, b, c, d:Real):Real;
begin
returnVote:= a+(2 * b) - (c / 2) - (d / 4);

end;

begin
writeln('Programma per calcolare il voto fornendo il numero di risposte esatte,');
writeln('quelle esatte e incomplete, quelle sbagliate e quelle non date');
writeln('=====================================================================');
writeln('Fornire il nome dello studente: ');
read(nome);
writeln('Fornire il numero di risposte esatte e complete: ');
read(EC);
writeln('Fornire il numero di risposte esatte ma incomplete: ');
read(El);
writeln('Fornire il numero di risposte sbagliate: ');
read(S);
writeln('Fornire il numero di risposte non date: ');
read(N);
writeln('Il voto calcolato per lo studente ', nome,' e di: ', returnVote(El, EC, S, N):3:1);
readln();
end.
emjay

When the user inputs the last number and presses enter, the number is written into the N variable, but the enter remains in the buffer. So when the program reaches the last readln(), it reads that enter and exits.

To prevent this, you should replace all your reads with readlns (or at least the last one).

That said, it's not good practice to use readln when you need to see what your program has written in the output. If you are using old IDE's like Turbo Pascal, then there is a menu item which shows you the output after the program was terminated. Modern IDE's will not close the window, and if you are not using any IDE, then you can probably see the output in your console.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

C Program crashes after last input

From Dev

QMainWindow closes right after show()

From Dev

Program is hanging after input

From Dev

Program blocks after input

From Dev

Program is hanging after input

From Dev

'Workbook.open' error - Closes the file right after opening it

From Dev

std::cin does not accept input, program closes immediately

From Dev

Tkinter window closes automatically after Python program has run in PyCharm

From Dev

launch exe with params, but program closes instantly after opening?

From Dev

Tkinter window closes automatically after Python program has run in PyCharm

From Dev

Angular: Dropdown menu closes too quickly after input loses focus

From Dev

Invoke click event file input after $mdDialog closes

From Dev

C program compiles, but terminates right after execution

From Dev

GWT: SetBackgroundColor of a FormPanel right after starting the program

From Dev

Program crashes after popping the last element of the stack

From Dev

Program immediately closes in SDL

From Dev

Focus on input right after its creation

From Dev

batch file on network share closes right away after 'Run as administrator' is selected

From Dev

Program does not return "Correct" even when the right answer is input

From Dev

after compiling python program, how to input arguments

From Dev

Java documentlistener - program stop working after input

From Dev

Start a program after waiting for user input

From Dev

Rebooting program after input() automatically on python

From Dev

Program ends after user input is invalid

From Dev

Simple "Hello World" style program closes extremely soon after execution starts

From Dev

Simple "Hello World" style program closes extremely soon after execution starts

From Dev

How can I keep the gnome-terminal open after a program closes?

From Dev

Add the last added database record right after form submission

From Dev

Add the last added database record right after form submission

Related Related

  1. 1

    C Program crashes after last input

  2. 2

    QMainWindow closes right after show()

  3. 3

    Program is hanging after input

  4. 4

    Program blocks after input

  5. 5

    Program is hanging after input

  6. 6

    'Workbook.open' error - Closes the file right after opening it

  7. 7

    std::cin does not accept input, program closes immediately

  8. 8

    Tkinter window closes automatically after Python program has run in PyCharm

  9. 9

    launch exe with params, but program closes instantly after opening?

  10. 10

    Tkinter window closes automatically after Python program has run in PyCharm

  11. 11

    Angular: Dropdown menu closes too quickly after input loses focus

  12. 12

    Invoke click event file input after $mdDialog closes

  13. 13

    C program compiles, but terminates right after execution

  14. 14

    GWT: SetBackgroundColor of a FormPanel right after starting the program

  15. 15

    Program crashes after popping the last element of the stack

  16. 16

    Program immediately closes in SDL

  17. 17

    Focus on input right after its creation

  18. 18

    batch file on network share closes right away after 'Run as administrator' is selected

  19. 19

    Program does not return "Correct" even when the right answer is input

  20. 20

    after compiling python program, how to input arguments

  21. 21

    Java documentlistener - program stop working after input

  22. 22

    Start a program after waiting for user input

  23. 23

    Rebooting program after input() automatically on python

  24. 24

    Program ends after user input is invalid

  25. 25

    Simple "Hello World" style program closes extremely soon after execution starts

  26. 26

    Simple "Hello World" style program closes extremely soon after execution starts

  27. 27

    How can I keep the gnome-terminal open after a program closes?

  28. 28

    Add the last added database record right after form submission

  29. 29

    Add the last added database record right after form submission

HotTag

Archive