so i'm writing program pascal , asking me repeat program until no name entered this exact question if helps
so found out meaning null/empty in pascal ''
tried different codes last 1 tried
program lunch; const dues_percentage1=0.3; dues_percentage2=0.2; var name:string; age:integer; lunch_money:real; dues:real; begin while name <> '' writeln('please enter name'); read(name); writeln('please enter age'); read(age); writeln('please enter amount of money receive'); read(lunch_money); if age >10 dues:= lunch_money*dues_percentage1 else dues:= lunch_money*dues_percentage2; writeln('the amount of lunch money receive $',lunch_money:4:2); writeln('the amount of dues pay $',dues:3:2); readln(dues,lunch_money); end.
and doesn't work appreciate help.
the problem if use while loop, need initialise "name" before make test (and read before each next test within loop). example:
var name : string; begin //initialise name readln(name); while name <> '' begin // stuff here // , here //then read next name readln(name); end; end;
note while carries out next statement (if condition true), need use compound statement if want while more 1 statement.
if use repeat until may need different structure:
var name : string; begin repeat readln(name); if name <> '' begin // stuff here // , here end; until name = ''; end;
Comments
Post a Comment