please help me with easy sentinel program. - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

please help me with easy sentinel program.

babybossbabyboss Posts: 1Member
I am doing a program it requires for press a key to exit
this is what I have done, but can't figure out how to keep doing.
program TestGrades;

uses crt;
const
Sentinel = -1;

var {Declare Variables}
NumberGrade, {Number of Grade is entering by user}
Counter,
Grade : integer;
Average,
Total : real;
{---------------------------------------------------------------}
begin {Main Program}
clrscr;

NumberGrade:=0;
Total:=0.0;
begin
repeat
write('Enter a grade or ', Sentinel, ' : ');
readln(Grade);
if Grade <> Sentinel then
begin NumberGrade := NumberGrade + 1;
end;
until Grade = Sentinel;
Total := Total + Grade;
end;
writeln;
writeln('The Total is ', Total:1:2);
Average := Total/NumberGrade;
writeln('The Average is ' ,Average:1:2);
readln
end.

Please help thx!

Comments

  • richard_wise25richard_wise25 Posts: 52Member
    : I am doing a program it requires for press a key to exit
    : this is what I have done, but can't figure out how to keep doing.
    I do not understand what you mean by 'keep doing'? keep doing wot???
    If you mean you want the program to keep on repeating until the person presses a certain key then thats easy.
    var
    response: char;
    begin
    ...
    ...
    ...
    repeat
    ...
    ...
    ...
    ...
    ...
    ...
    ...
    ...
    response:=readkey;
    until response='q';
    ...
    end.

    where you replace q with the letter you want to exit when pressed.
  • viv.viv. Posts: 72Member
    dude, u gotta put a ; after your last readln.
    and if u just want to end the program on pressin a key , try this
    [ uses crt;
    var anything:char;
    BEGIN
    anything:=readkey;
    END.
    ]

    doing this makes the user not have to press enter.





Sign In or Register to comment.