| | |
Ordinal types
Please support our Pascal and Delphi advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
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;
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.
Thanks in advance guys!
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;
Pascal and Delphi Syntax (Toggle Plain Text)
[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'
Here is what I have so far, sorry for the language, I'm doing IT in an Afrikaans school.
delphi Syntax (Toggle Plain Text)
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!
Last edited by prefer; Oct 4th, 2009 at 10:32 am. Reason: Wrong code
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...
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...

delphi Syntax (Toggle Plain Text)
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}
Be a good part of the community.Don't be ungrateful.
If you ask something on the forum and you got the right answer then mark as solved!
If my opinion helped to you a lot then sometimes give reputation point to me.
I'm just a pascal programmer from Hungary.
Farewell...
If you ask something on the forum and you got the right answer then mark as solved!
If my opinion helped to you a lot then sometimes give reputation point to me.
I'm just a pascal programmer from Hungary.
Farewell...
•
•
Join Date: Oct 2008
Posts: 16
Reputation:
Solved Threads: 3
0
#4 Oct 7th, 2009
You can also change your variables to ordinal types like integers...and to divide you use 'div'
Pascal and Delphi Syntax (Toggle Plain Text)
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.
![]() |
Similar Threads
- Playing with shared memory - problem with non 'simple' data types (C++)
- DNS record types (PHP)
- C++ Data Types (C++)
Other Threads in the Pascal and Delphi Forum
- Previous Thread: How to find the most common word in a Linked List in Pascal.
- Next Thread: RichEdit and Autoscroll
| Thread Tools | Search this Thread |






