Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Case Statements: HELLLPPPP!!!!!

Status
Not open for further replies.

Horsleym

Programmer
Oct 9, 2001
9
GB
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
 
Since there is more than one statement in each of your "cases" you need begins and ends - like this

case iNumber of
        1: begin
x:=r+s;
        writeReal (Display, x, 2, 5);
end;
        2: begin
x:=r-s;
         writeReal (Display, x, 2, 5);
end

etc...

TealWren
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top