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.
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 read
s with readln
s (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.
Comments