fork download
  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6. System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  7. FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls,
  8. FMX.Controls.Presentation, FMX.Edit;
  9.  
  10. type
  11. TForm1 = class(TForm)
  12. ImageControl1: TImageControl;
  13. Label1: TLabel;
  14. Label2: TLabel;
  15. Edit1: TEdit;
  16. Label3: TLabel;
  17. Label4: TLabel;
  18. Button1: TButton;
  19. procedure Button1Click(Sender: TObject);
  20. private
  21. { Private declarations }
  22. public
  23. { Public declarations }
  24. end;
  25.  
  26. var
  27. Form1: TForm1;
  28.  
  29. implementation
  30.  
  31. {$R *.fmx}
  32. {$R *.NmXhdpiPh.fmx ANDROID}
  33. {$R *.SmXhdpiPh.fmx ANDROID}
  34.  
  35. procedure TForm1.Button1Click(Sender: TObject);
  36. var
  37. score: integer;
  38. grade: string;
  39. begin
  40. // ตรวจสอบว่าผู้ใช้ป้อนค่าหรือไม่
  41. if Edit1.Text = '' then
  42. begin
  43. ShowMessage('กรุณาป้อนคะแนนก่อน');
  44. end;
  45.  
  46. // ตรวจสอบว่าค่าที่ป้อนเป็นตัวเลขหรือไม่
  47. if not TryStrToInt(Edit1.Text, score) then
  48. begin
  49. ShowMessage('กรุณาป้อนค่าตัวเลขเท่านั้น');
  50. end;
  51.  
  52. // ตรวจสอบว่าคะแนนอยู่ในช่วงที่ถูกต้อง (0-100)
  53. if (score < 0) or (score > 100) then
  54. begin
  55. ShowMessage('กรุณาป้อนคะแนนระหว่าง 0 ถึง 100');
  56. end;
  57.  
  58. // กำหนดเกรดตามช่วงคะแนน
  59. if (score >= 80) and (score <= 100) then
  60. grade := 'A'
  61. else if (score >= 70) and (score < 80) then
  62. grade := 'B'
  63. else if (score >= 60) and (score < 70) then
  64. grade := 'C'
  65. else if (score >= 50) and (score < 60) then
  66. grade := 'D'
  67. else
  68. grade := 'F';
  69.  
  70. // แสดงผลเกรดใน Label4
  71. Label4.Text := 'Grade: ' + grade;
  72.  
Success #stdin #stdout 0.03s 25872KB
stdin
Standard input is empty
stdout
unit Unit1;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls,
  FMX.Controls.Presentation, FMX.Edit;

type
  TForm1 = class(TForm)
    ImageControl1: TImageControl;
    Label1: TLabel;
    Label2: TLabel;
    Edit1: TEdit;
    Label3: TLabel;
    Label4: TLabel;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.fmx}
{$R *.NmXhdpiPh.fmx ANDROID}
{$R *.SmXhdpiPh.fmx ANDROID}

procedure TForm1.Button1Click(Sender: TObject);
var
  score: integer;
  grade: string;
begin
  // ตรวจสอบว่าผู้ใช้ป้อนค่าหรือไม่
  if Edit1.Text = '' then
  begin
    ShowMessage('กรุณาป้อนคะแนนก่อน');
    Exit;
  end;

  // ตรวจสอบว่าค่าที่ป้อนเป็นตัวเลขหรือไม่
  if not TryStrToInt(Edit1.Text, score) then
  begin
    ShowMessage('กรุณาป้อนค่าตัวเลขเท่านั้น');
    Exit;
  end;

  // ตรวจสอบว่าคะแนนอยู่ในช่วงที่ถูกต้อง (0-100)
  if (score < 0) or (score > 100) then
  begin
    ShowMessage('กรุณาป้อนคะแนนระหว่าง 0 ถึง 100');
    Exit;
  end;

  // กำหนดเกรดตามช่วงคะแนน
  if (score >= 80) and (score <= 100) then  
    grade := 'A'
  else if (score >= 70) and (score < 80) then  
    grade := 'B'
  else if (score >= 60) and (score < 70) then  
    grade := 'C'
  else if (score >= 50) and (score < 60) then  
    grade := 'D'
  else  
    grade := 'F';

  // แสดงผลเกรดใน Label4
  Label4.Text := 'Grade: ' + grade;
end;

end.