Hi everyone!

I think I'll be on here allot from now on, pretty useful forum, well done!

Anyways, I'm doing a project for school and it's got me stuck.
See I didn't understand the error message the compiler gave me at first, but then I read it on ...some website, it says that the Float/Real variable types are not a valid ordinal type?

Basically what I need to do is create a program that would ask for six grade points, and then give a average and the symbol they reached.
Here is the error messages I received;

[Error] gradering.pas(49): Ordinal type required
[Error] gradering.pas(63): '.' expected but ';' found
[Fatal Error] gradering_p.dpr(5): Could not compile used unit 'gradering.pas'

I'm first focusing on the first error, then moving on to the second one, help with that would be appreciated as well.

Here is what I have so far, sorry for the language, I'm doing IT in an Afrikaans school.

unit gradering;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, ExtCtrls;

type
  TfrmGradering = class(TForm)
    pnlAgtergrond: TPanel;
    lblPunt: TLabel;
    lblAf_punt: TLabel;
    lblPunt2: TLabel;
    edtPunt: TEdit;
    lblAfvoer: TLabel;
    bmbRetry: TBitBtn;
    bmbClose: TBitBtn;
    btnTel: TButton;
    procedure btnTelClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmGradering: TfrmGradering;
  iTeller : integer;
  rTotaal, rGemiddeld : real;
  sSimbool, sAfvoer : string;

implementation

{$R *.dfm}

procedure TfrmGradering.btnTelClick(Sender: TObject);
begin

  if iTeller < 6 then
    begin
      Inc(iTeller, 1);
      rTotaal := rTotaal + StrToInt(edtPunt.Text);
      lblAf_punt.Caption := IntToStr(iTeller);
    end
  else if iTeller = 6 then
    begin
      rGemiddeld := ((rTotaal / 6) * 100);
      case rGemiddeld of
         80..100 : sSimbool := 'A';
         70..79  : sSimbool := 'B';
         60..69  : sSimbool := 'C';
         50..59  : sSimbool := 'D';
         40..49  : sSimbool := 'E';
         30..39  : sSimbool := 'F';
         20..29  : sSimbool := 'G';
         else sSimbool := 'H';
      end
  end

end;

end;

end.

Thanks in advance guys!

Dani AI

Generated

The compile error was caused by using a floating-point value where Pascal's case expects an ordinal type. Both and offered valid quick fixes (convert the computed average to an integer, or keep totals as integers and use div). The following clarifies the trade-offs and adds safer patterns for input parsing, rounding behavior, and initialization.

A simple, robust pattern is:

  • parse each edit with TryStrToInt and reject out-of-range entries (0..100);
  • keep a running integer total and a counter;
  • compute a floating-point average for display, but map the average to a grade with an if/else chain (avoids case restrictions and clarifies boundaries).

Example helper (new mapping approach):

function GradeSymbolFromAverage(Avg: Double): string;
begin
  if Avg >= 80.0 then Exit('A');
  if Avg >= 70.0 then Exit('B');
  if Avg >= 60.0 then Exit('C');
  if Avg >= 50.0 then Exit('D');
  if Avg >= 40.0 then Exit('E');
  if Avg >= 30.0 then Exit('F');
  if Avg >= 20.0 then Exit('G');
  Result := 'H';
end;

Parsing and usage notes:

var mark: Integer;
if not TryStrToInt(edtPunt.Text, mark) then
  ShowMessage('Enter a whole-number mark');
if (mark < 0) or (mark > 100) then
  ShowMessage('Mark must be 0..100');
total := total + mark;
Inc(counter);
if counter = 6 then
  sSimbool := GradeSymbolFromAverage(total / 6.0);

Important cautions: do not multiply the average by 100 if marks are already 0..100 (that will blow up the scale); only multiply when converting from a 0..1 fractional input. Decide explicitly on rounding policy: Round will push 79.5 to 80 (grade B), while truncation keeps 79 (grade C). Initialize counters/totals in FormCreate or a Reset handler and disable the Add button when six marks are entered to avoid off-by-one logic. These steps improve safety and make the grading logic predictable.

Recommended Answers

All 3 Replies

I tryed to compile your unit,same problem like you,mine is delphi 7.
The case statement is waiting for an ordinal type as char or integer,or byte or boolean etc and you add a real type...it is the problem :'(
One of alternative is to round to integer,look at the modified unit
Of course to much end written by you that fixed by me... :D

unit gradering;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, ExtCtrls;

type
  TfrmGradering = class(TForm)
    pnlAgtergrond: TPanel;
    lblPunt: TLabel;
    lblAf_punt: TLabel;
    lblPunt2: TLabel;
    edtPunt: TEdit;
    lblAfvoer: TLabel;
    bmbRetry: TBitBtn;
    bmbClose: TBitBtn;
    btnTel: TButton;
    procedure btnTelClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmGradering: TfrmGradering;
  iTeller : integer;
  rTotaal, rGemiddeld : real;
  sSimbool, sAfvoer : string;

implementation

{$R *.dfm}

procedure TfrmGradering.btnTelClick(Sender: TObject);
begin

  if iTeller < 6 then
    begin
      Inc(iTeller, 1);
      rTotaal := rTotaal + StrToInt(edtPunt.Text);
      lblAf_punt.Caption := IntToStr(iTeller);
    end {if}
  else if iTeller = 6 then
    begin
      rGemiddeld := ((rTotaal / 6) * 100);
      case Round(rGemiddeld) of
         80..100 : sSimbool := 'A';
         70..79  : sSimbool := 'B';
         60..69  : sSimbool := 'C';
         50..59  : sSimbool := 'D';
         40..49  : sSimbool := 'E';
         30..39  : sSimbool := 'F';
         20..29  : sSimbool := 'G';
         else sSimbool := 'H';
      end ;{case}
  end; {else if begin}

end;{proc}

end. {unit}

Hey... that works!
Just added my final result messages, and compiled it without an error.
Now everything works as it says in my book! ;)

Thank you. :)

You can also change your variables to ordinal types like integers...and to divide you use 'div'

var
  frmGradering: TfrmGradering;
  iTeller : integer;
  iTotaal, iGemiddeld : integer;
  sSimbool, sAfvoer : string;

implementation

{$R *.dfm}

procedure TfrmGradering.btnTelClick(Sender: TObject);
begin
  if iTeller < 6 then
  begin
  Inc(iTeller, 1);
  iTotaal := iTotaal + StrToInt(edtPunt.Text);
  lblAf_punt.Caption := IntToStr(iTeller);
  end {if}
  else if iTeller = 6 then
  begin
    iGemiddeld := ((iTotaal div 6) * 100);

    case iGemiddeld of

    80..100 : sSimbool := 'A';

    70..79 : sSimbool := 'B';

    60..69 : sSimbool := 'C';

    50..59 : sSimbool := 'D';

    40..49 : sSimbool := 'E';

    30..39 : sSimbool := 'F';

    20..29 : sSimbool := 'G';

    else sSimbool := 'H';
    end ;{case}
  end; {else if begin}
end;{proc}
end.
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.