Im writing a program at the moment at college and im using case statements. I want to do some maths under the
case of
section but it keeps saying 'Constant expression expected' What I need to know is how to display the result of my calcualtions.
writeReal (Display, x, 2, 5) doesnt work.
This is the code im getting the errors from..
procedure TForm1.BtnRUNClick(Sender: TObject);
{Asks for two real numbers & will carry out a chosen calculation of them}
var r, s, x:real;
iNumber :integer;
begin
clear (Display);
Application.MessageBox('This procedure will ask you for two real numbers & make your chosen calcualtion of them', 'Information', 0);
getReal (r, 'Please enter a real number:');
write (Display, 'Real number 1 = ');
writeReal (Display, r, 2, 5);
writeln (Display);
getReal (s, 'Please enter a real number:');
write (Display, 'Real number 2 = ');
writeReal (Display, s, 2, 5);
writeln (Display);
writeln (Display);
write (Display, 'Please choose a number from the following menu:');
writeln (Display);
writeln (Display);
write (Display, '1 = To Add');
writeln (Display);
write (Display, '2 = To Subtract');
writeln (Display);
write (Display, '3 = To Multiply');
writeln (Display);
write (Display, '4 = To Divide');
writeln (Display);
getInt (iNumber, 'Please enter a number:');
case iNumber of
1: x:=r+s;
writeReal (Display, x, 2, 5);
2: x:=r-s;
writeReal (Display, x, 2, 5);
3: x:=r*s;
writeReal (Display, x, 2, 5);
4; x:=r/s;
writeReal (Display, x, 2, 5);
else
ShowMessage ('You have chosen an invalid number');
end;
end;
end.
Any help would be much appreciated
Thanks
Mark
case of
section but it keeps saying 'Constant expression expected' What I need to know is how to display the result of my calcualtions.
writeReal (Display, x, 2, 5) doesnt work.
This is the code im getting the errors from..
procedure TForm1.BtnRUNClick(Sender: TObject);
{Asks for two real numbers & will carry out a chosen calculation of them}
var r, s, x:real;
iNumber :integer;
begin
clear (Display);
Application.MessageBox('This procedure will ask you for two real numbers & make your chosen calcualtion of them', 'Information', 0);
getReal (r, 'Please enter a real number:');
write (Display, 'Real number 1 = ');
writeReal (Display, r, 2, 5);
writeln (Display);
getReal (s, 'Please enter a real number:');
write (Display, 'Real number 2 = ');
writeReal (Display, s, 2, 5);
writeln (Display);
writeln (Display);
write (Display, 'Please choose a number from the following menu:');
writeln (Display);
writeln (Display);
write (Display, '1 = To Add');
writeln (Display);
write (Display, '2 = To Subtract');
writeln (Display);
write (Display, '3 = To Multiply');
writeln (Display);
write (Display, '4 = To Divide');
writeln (Display);
getInt (iNumber, 'Please enter a number:');
case iNumber of
1: x:=r+s;
writeReal (Display, x, 2, 5);
2: x:=r-s;
writeReal (Display, x, 2, 5);
3: x:=r*s;
writeReal (Display, x, 2, 5);
4; x:=r/s;
writeReal (Display, x, 2, 5);
else
ShowMessage ('You have chosen an invalid number');
end;
end;
end.
Any help would be much appreciated
Thanks
Mark