samedi 30 septembre 2017

can i use case inside if statement in pascal

i want to using case on if statement, can i use it? because i always got error when i compile it ;w;

error i got : Tahun.pas(26,21) Fatal: Syntax error, ";" expected but "ELSE" found Tahun.pas(0) Fatal: Compilation aborted

here my code :

uses Crt;
var
sisa, bulan, tahun : integer;

begin
ClrScr;
writeln('masukkan tahun'); read(tahun);
sisa := tahun mod 4;
if sisa =0 then
writeln('masukkan bulan 1-12'), read(bulan);
 case bulan of
  1: write('31');
  2: write('29');
  3: write('31');
  4: write('30');
  5: write('31');
  6: write('30');
  7: write('31');
  8: write('30');
  9: write('31');
  10: write('30');
  11: write('31');
  12: write('30');
  else write('bulan tidak lebih dari 12');
end;
else
writeln('masukkan bulan 1-12'), read(bulan);
 case bulan of
  1: write('31');
  2: write('28');
  3: write('31');
  4: write('30');
  5: write('31');
  6: write('30');
  7: write('31');
  8: write('30');
  9: write('31');
  10: write('30');
  11: write('31');
  12: write('30');
else write('bulan tidak lebih dari 12')
end;
 readln;
 readln;

end.

or maybe you know how to improve the code? ;w;

Thank you for answering ;w;

Aucun commentaire:

Enregistrer un commentaire