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');
Readln(CharUserInput);
(*Enter Base and Height*);
Writeln('Enter Base ');
Readln(Base);
Writeln('Enter Height ');
Readln(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

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 ');
Readln(Room);
Writeln('Enter Capacity ');
Readln(Capacity);
Writeln('Enter Enrollment ');
Readln(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?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.