program AreaofRectangleOrTriangle;

uses
WinCrt;

var

Base, Height, RectOrTrian,
Area, CharUserInput: Char;

Begin

(*Enter R or T*);
Writeln('Enter R for Rectangle or T for Triangle');
(*Enter Base and Height*);
Writeln('Enter Base ');
Writeln('Enter Height ');
(*Give case statement and formulas*);
if (CharUserInput = 'R') or (CharUserInput = 'r') then
Area := Base * Height
else if (CharUserInput = 'T') or (CharUserInput = 't') then
Area := .5 * Base * Height;
(*Print to screen*);
Writeln('Area is ');

End.

It keeps stopping on the else statement...and I cannot for the life of me figure it out...can someone tell me how to do this?
thanks

3
Contributors
4
Replies
5
Views
11 Years
Discussion Span
Last Post by needs_help

Hi,

Unlike C and C++, in Delphi and Pascal char only denotes AlphaNumerical single charactr and can't be used for arithmetic operations. I propose those types :

Base, Height : integer;
Area : single;
RectOrTrian,CharUserInput: Char;

Area can became floating point on triangle case because of the multiplication with half, and you don't need to use ; on comment lines. And I suppose you omited the variable Area on last writeln.

Loren Soth

Thank you...I did it a little different, and was able to get it to work but about the same.

I am trying to teach myself how to program, and here is another one in the book I am having trouble with. It is suppose to display appropriate information below each one of the catagories.

program ClassOccupancy;

uses
WinCrt;

var

Room, Capacity, Enrollment, EmptySeats,
Filled, NotFilled: Real;

Begin

(*Enter data*);
Writeln('Enter room ');
Writeln('Enter Capacity ');
Writeln('Enter Enrollment ');
(*Emptyseats is equal to capacity minus enrollment*);
EmptySeats := Capacity - Enrollment;
(*if capacity is greater then enrollment then filled if not then notfilled*);
If Capacity > Enrollment then
Writeln('Not Filled')
Else
Writeln('Filled');
Writeln(Room:10, Capacity:10, Enrollment:10, EmptySeats:10, Filled/NotFilled:10);
End.

How doesn't this work?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.