944,174 Members | Top Members by Rank

Ad:
Oct 4th, 2009
-1

Ordinal types

Expand Post »
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;
Pascal and Delphi Syntax (Toggle Plain Text)
  1. [Error] gradering.pas(49): Ordinal type required
  2. [Error] gradering.pas(63): '.' expected but ';' found
  3. [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.
delphi Syntax (Toggle Plain Text)
  1. unit gradering;
  2.  
  3. interface
  4.  
  5. uses
  6. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7. Dialogs, StdCtrls, Buttons, ExtCtrls;
  8.  
  9. type
  10. TfrmGradering = class(TForm)
  11. pnlAgtergrond: TPanel;
  12. lblPunt: TLabel;
  13. lblAf_punt: TLabel;
  14. lblPunt2: TLabel;
  15. edtPunt: TEdit;
  16. lblAfvoer: TLabel;
  17. bmbRetry: TBitBtn;
  18. bmbClose: TBitBtn;
  19. btnTel: TButton;
  20. procedure btnTelClick(Sender: TObject);
  21. private
  22. { Private declarations }
  23. public
  24. { Public declarations }
  25. end;
  26.  
  27. var
  28. frmGradering: TfrmGradering;
  29. iTeller : integer;
  30. rTotaal, rGemiddeld : real;
  31. sSimbool, sAfvoer : string;
  32.  
  33. implementation
  34.  
  35. {$R *.dfm}
  36.  
  37. procedure TfrmGradering.btnTelClick(Sender: TObject);
  38. begin
  39.  
  40. if iTeller < 6 then
  41. begin
  42. Inc(iTeller, 1);
  43. rTotaal := rTotaal + StrToInt(edtPunt.Text);
  44. lblAf_punt.Caption := IntToStr(iTeller);
  45. end
  46. else if iTeller = 6 then
  47. begin
  48. rGemiddeld := ((rTotaal / 6) * 100);
  49. case rGemiddeld of
  50. 80..100 : sSimbool := 'A';
  51. 70..79 : sSimbool := 'B';
  52. 60..69 : sSimbool := 'C';
  53. 50..59 : sSimbool := 'D';
  54. 40..49 : sSimbool := 'E';
  55. 30..39 : sSimbool := 'F';
  56. 20..29 : sSimbool := 'G';
  57. else sSimbool := 'H';
  58. end
  59. end
  60.  
  61. end;
  62.  
  63. end;
  64.  
  65. end.

Thanks in advance guys!
Last edited by prefer; Oct 4th, 2009 at 10:32 am. Reason: Wrong code
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
prefer is offline Offline
3 posts
since Oct 2009
Oct 4th, 2009
1

Re: Ordinal types

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...
delphi Syntax (Toggle Plain Text)
  1.  
  2. unit gradering;
  3.  
  4. interface
  5.  
  6. uses
  7. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  8. Dialogs, StdCtrls, Buttons, ExtCtrls;
  9.  
  10. type
  11. TfrmGradering = class(TForm)
  12. pnlAgtergrond: TPanel;
  13. lblPunt: TLabel;
  14. lblAf_punt: TLabel;
  15. lblPunt2: TLabel;
  16. edtPunt: TEdit;
  17. lblAfvoer: TLabel;
  18. bmbRetry: TBitBtn;
  19. bmbClose: TBitBtn;
  20. btnTel: TButton;
  21. procedure btnTelClick(Sender: TObject);
  22. private
  23. { Private declarations }
  24. public
  25. { Public declarations }
  26. end;
  27.  
  28. var
  29. frmGradering: TfrmGradering;
  30. iTeller : integer;
  31. rTotaal, rGemiddeld : real;
  32. sSimbool, sAfvoer : string;
  33.  
  34. implementation
  35.  
  36. {$R *.dfm}
  37.  
  38. procedure TfrmGradering.btnTelClick(Sender: TObject);
  39. begin
  40.  
  41. if iTeller < 6 then
  42. begin
  43. Inc(iTeller, 1);
  44. rTotaal := rTotaal + StrToInt(edtPunt.Text);
  45. lblAf_punt.Caption := IntToStr(iTeller);
  46. end {if}
  47. else if iTeller = 6 then
  48. begin
  49. rGemiddeld := ((rTotaal / 6) * 100);
  50. case Round(rGemiddeld) of
  51. 80..100 : sSimbool := 'A';
  52. 70..79 : sSimbool := 'B';
  53. 60..69 : sSimbool := 'C';
  54. 50..59 : sSimbool := 'D';
  55. 40..49 : sSimbool := 'E';
  56. 30..39 : sSimbool := 'F';
  57. 20..29 : sSimbool := 'G';
  58. else sSimbool := 'H';
  59. end ;{case}
  60. end; {else if begin}
  61.  
  62. end;{proc}
  63.  
  64. end. {unit}
Reputation Points: 132
Solved Threads: 138
Posting Pro
FlamingClaw is offline Offline
559 posts
since Feb 2009
Oct 4th, 2009
0

Re: Ordinal types

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
prefer is offline Offline
3 posts
since Oct 2009
Oct 7th, 2009
0
Re: Ordinal types
You can also change your variables to ordinal types like integers...and to divide you use 'div'
Pascal and Delphi Syntax (Toggle Plain Text)
  1. var
  2. frmGradering: TfrmGradering;
  3. iTeller : integer;
  4. iTotaal, iGemiddeld : integer;
  5. sSimbool, sAfvoer : string;
  6.  
  7. implementation
  8.  
  9. {$R *.dfm}
  10.  
  11. procedure TfrmGradering.btnTelClick(Sender: TObject);
  12. begin
  13. if iTeller < 6 then
  14. begin
  15. Inc(iTeller, 1);
  16. iTotaal := iTotaal + StrToInt(edtPunt.Text);
  17. lblAf_punt.Caption := IntToStr(iTeller);
  18. end {if}
  19. else if iTeller = 6 then
  20. begin
  21. iGemiddeld := ((iTotaal div 6) * 100);
  22.  
  23. case iGemiddeld of
  24.  
  25. 80..100 : sSimbool := 'A';
  26.  
  27. 70..79 : sSimbool := 'B';
  28.  
  29. 60..69 : sSimbool := 'C';
  30.  
  31. 50..59 : sSimbool := 'D';
  32.  
  33. 40..49 : sSimbool := 'E';
  34.  
  35. 30..39 : sSimbool := 'F';
  36.  
  37. 20..29 : sSimbool := 'G';
  38.  
  39. else sSimbool := 'H';
  40. end ;{case}
  41. end; {else if begin}
  42. end;{proc}
  43. end.
Reputation Points: 10
Solved Threads: 4
Newbie Poster
House_of_Dexter is offline Offline
17 posts
since Oct 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Pascal and Delphi Forum Timeline: How to find the most common word in a Linked List in Pascal.
Next Thread in Pascal and Delphi Forum Timeline: RichEdit and Autoscroll





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC