Ordinal types

Please support our Pascal and Delphi advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Oct 2009
Posts: 3
Reputation: prefer is an unknown quantity at this point 
Solved Threads: 0
prefer's Avatar
prefer prefer is offline Offline
Newbie Poster

Ordinal types

 
-1
  #1
Oct 4th, 2009
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.
  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
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 451
Reputation: FlamingClaw will become famous soon enough FlamingClaw will become famous soon enough 
Solved Threads: 108
FlamingClaw's Avatar
FlamingClaw FlamingClaw is offline Offline
Posting Pro in Training

Re: Ordinal types

 
1
  #2
Oct 4th, 2009
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...
  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}
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...
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 3
Reputation: prefer is an unknown quantity at this point 
Solved Threads: 0
prefer's Avatar
prefer prefer is offline Offline
Newbie Poster

Re: Ordinal types

 
0
  #3
Oct 4th, 2009
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.
I can really anything I could ever imagine with PHP and my five years of experience, but when it comes to Delphi *sigh* I always seem to need help. :'(
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 16
Reputation: House_of_Dexter is an unknown quantity at this point 
Solved Threads: 3
House_of_Dexter House_of_Dexter is offline Offline
Newbie Poster
 
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)
  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.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC