Fórum De novo; agora formatado. #593155

15/05/2018

0

unit Media;

interface

uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type
TForm1 = class(TForm)
Nota1: TLabel;
Nota2: TLabel;
Media: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
Var
Nota1, Nota2: Integer;
Media: Real;

begin
Nota1:= StrToInt (Edit1.Text);
Nota2:= StrToInt (Edit2.Text);
Media:= (Nota1 + Nota2) / 2;
Media:= RealToStr (Media);

end;


end.

Valeu.
Adriano Freitas

Adriano Freitas

Responder

Posts

15/05/2018

Natanael Ferreira

Primeiramente, troque o nome do seu Label "Media" (exemplo, troque para lblMedia) porque está conflitando com o nome da sua variável "Media" do tipo real.

Segundo, RealToStr não existe. Troque por FloatToStr.

Exemplo:

Var
  Nota1, Nota2: Integer;
  Media: Real;
begin
  Nota1 := StrToInt(Edit1.Text);
  Nota2 := StrToInt(Edit2.Text);
  Media := (Nota1 + Nota2) / 2;
  lblMedia.Caption := FloatToStr(Media);
end;
Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar