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

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.