Fórum Ajuda com programa simples #593154
15/05/2018
0
Não estou conseguindo executar um programa que calcula a média de dois números (Sou iniciante).
Lá vai:
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.
O erro:
[dcc32 Error] Media.pas(41): E2003 Undeclared identifier: 'RealToStr'
Se alguém puder reescrever, agradeceria muito.
Abraço.
Adriano Freitas
Curtir tópico
+ 0Post mais votado
15/05/2018
Iure Caldas
Gostei + 1
Mais Posts
15/05/2018
Iure Caldas
testei aqui, é isso mesmo, veja:
procedure TForm1.Button1Click(Sender: TObject);
var
n1,n2: Integer;
media: Real;
begin
n1:= StrToInt(Edit1.Text);
n2:= StrToInt(Edit2.Text);
media:= (n1 + n2) / 2;
Edit3.Text:= FloatToStr(media);
end;
Gostei + 0
15/05/2018
Adriano Freitas
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: Float;
begin
Nota1:= StrToInt (Edit1.Text);
Nota2:= StrToInt (Edit2.Text);
Media:= (Nota1 + Nota2) / 2;
Media:= FloatToStr (Media);
end;
end.Erro:
[dcc32 Error] Media.pas(35): E2003 Undeclared identifier: 'Float'
É delphi starter.
Valew
Gostei + 1
15/05/2018
Natanael Ferreira
Exemplo:
Var Nota1, Nota2: Integer; Media: Real; begin Nota1 := StrToInt(Edit1.Text); Nota2 := StrToInt(Edit2.Text); Media := (Nota1 + Nota2) / 2; lblMedia.Caption := FloatToStr(Media); // Troquei o nome do label para lblMedia end;
Gostei + 1
Clique aqui para fazer login e interagir na Comunidade :)