You can use if statement for multiple conditional statement but it will be little bit messy.
For example :
program multiple_cond_if;
{$APPTYPE CONSOLE}
uses
SysUtils;
var
mark : integer;
begin
write('Your mark : ');
readln(mark);
write('Your grade is ');
if mark >= 90 then
writeln('A')
else
if mark >= 70 then
writeln('B')
else
if mark >= 60 then
writeln('C')
else
if mark >= 40 then
writeln('D')
else
writeln('E');
readln;
end.
Instead of using if … then statement, it will be easier using case … of statement :
program multiple_cond_case;{$APPTYPE CONSOLE}
uses
SysUtils;
var
mark : integer;
begin
write('Your mark : ');
readln(mark);
write('Your grade is ');
case mark of
0..39 : writeln('E');
40..59 : writeln('D');
60..69 : writeln('C');
70..89 : writeln('B');
90..100 : writeln('A');
end;
readln;
end.
0 comments:
Post a Comment