Re: CAN ANY ONE RE-DO THIS TO MAKE IT MORE EASYER?


[ DelphiLand Discussion Forum ]

Posted by webmaster Guido on March 30, 19103 at 21:47:26:

In Reply to: Re: CAN ANY ONE RE-DO THIS TO MAKE IT MORE EASYER? posted by Kevin -=-Laaaaaaaaatttteeee on March 29, 19103 at 15:57:02:

: : : Can anyone re=do this without changing the basic layout?
: : : Thanks
: : : Kev : Laaaaaattttteeeeeee

: : : procedure displayGrade(mark : integer);
: : : begin
: : : case mark of
: : : 0..49 : writeln('Fail');
: : : 50..64: writeln('Pass');
: : : 65..79: writeln('Credit');
: : : 80..100:writeln('Honours');
: : : else
: : : writeln('invalid entry');
: : : end; //case
: : : end;

: : : var
: : : Grade : integer;
: : : begin
: : : repeat
: : : Write('Enter Grade or mark (-1 to stop) >');
: : : readln(Grade);
: : : if Grade <> stop then
: : : displayGrade(Grade);
: : : until Grade = stop
: : : end.
: : ------------------

: : What do you mean by "redo this"? I think that this code can not be simplified, by leaving out whatever part you would break it.

: : But there is one statement missing, you have to declare "Stop". Add this right before the "var" statement:

: : const
: : Stop = -1;

: Thank you But what else can you use instead of case mark of? or with the numbers can you change the format of them ?
: Thankyou
----------------

You can replace the "CASE" with a series of IF... THEN... ELSE... but personally, I think that "CASE" is a lot easier to read.
The CASE code does the same thing as this:

procedure DisplayGrade(Mark : integer);
begin
   if (Mark > -1) and (Mark < 50) then WriteLn('Fail')
   else if Mark < 65 then WriteLn('Pass') 
   else if Mark < 80 then WriteLn('Credit') 
   else if Mark < 101 then WriteLn('Honours') 
   else WriteLn('invalid entry');
end; 
const
  Stop = -1;
var
  Grade : integer;
begin
  repeat
    Write('Enter Grade or mark (-1 to stop) >');
    ReadLn(Grade);
    if Grade <> Stop then
      DisplayGrade(Grade);
  until Grade = stop
end.

Related Articles and Replies:


[ DelphiLand Discussion Forum ]