I get the following errors in this code

Undeclared identifier 'Height' (Line 28)
'(' expected but ';' found (Line 51)

I havn't been learning Pascal for long, but I can't get why this doesn't work. All of my procedures are declared. The "Weight" one works fine but the "Height" one it says is unidentified. I can't for the life of me see why.

The procedure "Exit" isn't working either. It is the simplest procedure there...I don't see what it wrong with it.

Any help is greatly appreciated. Thanks :cheesy:

program Exercise3_4;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
   Selection : Char;
   WeightStones, HeightInches : Integer;
   WeightKilogrammes, HeightCentimetres : Real;

procedure CalculateWeight;
  begin
  WeightKilogrammes := WeightStones * 6.364;
  end;

procedure Weight;
  begin
    Writeln ('Please enter your weight in stones');
    Readln (WeightStones);
    Calculateweight;
    Writeln ('Your weight in kilogrammes is');
    Writeln (WeightKilogrammes:4:2);
    Writeln ('If you would like to return to the start, press r. If you wish to exit, press e');
    Readln (Selection);
      If Selection = 'e' then Exit;
      [B]If Selection = 'h' then Height; (Line 28)[/B]
    end;

procedure CalculateHeight;
  begin
    HeightCentimetres := HeightInches * 2.54;
  end;

procedure Height;
begin
    Writeln ('Please enter your height in inches');
    Readln (HeightInches);
    Calculateheight;
    Writeln ('Your height in centimetres is');
    Writeln (HeightCentimetres);
    Writeln ('If you would like to convert your weight from stones to kilogrammes, press w. If you wish to exit, press e');
    Readln (Selection);
      If Selection = 'e' then Exit;
      If Selection = 'w' then Weight;
    end;

procedure Exit;
begin
[B]Close; (Line 51)[/B]
end;

// Start of main program

begin
      Writeln ('If you would like to convert your weight from stones to kilogrammes, press w. If you would like to convert your height from inches to centimetres, press h. If you would like to exit, press e');
      Readln (Selection);
          if Selection = 'w' then Weight;
          if Selection = 'h' then Height;
          if Selection = 'e' then Exit;
end.

Edited 3 Years Ago by Dani: Fixed formatting

i think the problem is that your using the function height before its even declared. that maybe why your getting errors in height and not in weight

Hope this helps

I think that alvin_aldrich is right. But if You declare functin height before functin weight, at this time you will get a compiler error again becose You call weight from height. So, I think that you must declare height as forward. Some thing like:

program Exercise3_4;

{$APPTYPE CONSOLE}

uses
SysUtils;

procedure Height; forward;

var
Selection : Char;
WeightStones, HeightInches : Integer;
WeightKilogrammes, HeightCentimetres : Real;
...

It's work at TP7.

This article has been dead for over six months. Start a new discussion instead.