Problema aparentemente simples. Equação 2º Grau
04/04/2016
0
Olá, estou começando agora no delphi xe8. Estou tentando criar um aplicativo que calcule as raízes de uma equação do 2º grau e está dando o um erro.
[codeunit calcularaizesequação2grau;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.StdCtrls, Math;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
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
a, b, c,raiz1,raiz2,delta: Real;
begin
a := StrToFloat(Edit1.Text);
b := StrToFloat(Edit2.Text);
c := StrToFloat(Edit3.Text);
delta:= b^2 -4*a*c; <--- É AQUI. O DELPHI ESTÁ DIZENDO QUE FALTA UM PONTO E VÍRGULA DEPOIS DO 2! O ERRO DE
COMPILAÇÃO ESTÁ NO FINAL. FICA APARECENDO UMA LINHA VERMELHA EMBAIXO DO 2, QUE ESTÁ ELEVANDO O' B' AO QUADRADO.
begin
raiz1 := (-(b)+(sqrt(delta)))/2*a;
raiz1 := StrToFloat(Edit4.Text);
raiz2:= (-(b)-(sqrt(delta)))/2*a;
raiz2 := StrToFloat (Edit5.Text);
end;
end;
end.][/code]
[code[dcc32 Error] calcularaizesequação2grau.pas(48): E2017 Pointer type required][/code]
[img]http://arquivo.devmedia.com.br/forum/imagem/480368-20160404-174451.png[/img]
OPA, A EXPLICAÇÃO ESTÁ NA LINHA QUE O COMPILADOR ESTÁ REFERINDO.
VALEU!
[codeunit calcularaizesequação2grau;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.StdCtrls, Math;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
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
a, b, c,raiz1,raiz2,delta: Real;
begin
a := StrToFloat(Edit1.Text);
b := StrToFloat(Edit2.Text);
c := StrToFloat(Edit3.Text);
delta:= b^2 -4*a*c; <--- É AQUI. O DELPHI ESTÁ DIZENDO QUE FALTA UM PONTO E VÍRGULA DEPOIS DO 2! O ERRO DE
COMPILAÇÃO ESTÁ NO FINAL. FICA APARECENDO UMA LINHA VERMELHA EMBAIXO DO 2, QUE ESTÁ ELEVANDO O' B' AO QUADRADO.
begin
raiz1 := (-(b)+(sqrt(delta)))/2*a;
raiz1 := StrToFloat(Edit4.Text);
raiz2:= (-(b)-(sqrt(delta)))/2*a;
raiz2 := StrToFloat (Edit5.Text);
end;
end;
end.][/code]
[code[dcc32 Error] calcularaizesequação2grau.pas(48): E2017 Pointer type required][/code]
[img]http://arquivo.devmedia.com.br/forum/imagem/480368-20160404-174451.png[/img]
OPA, A EXPLICAÇÃO ESTÁ NA LINHA QUE O COMPILADOR ESTÁ REFERINDO.
VALEU!
Adriano Freitas
Curtir tópico
+ 0
Responder
Posts
04/04/2016
Natanael Ferreira
O sinal [b]^[/b] não funciona em Delphi.
Delphi tem uma função que chama Power(x,y), ela pertence a unit math.
Ela retorna x elevado a y.
Adicione [b]Math[/b] na uses e teste assim:
Delphi tem uma função que chama Power(x,y), ela pertence a unit math.
Ela retorna x elevado a y.
Adicione [b]Math[/b] na uses e teste assim:
var a, b, c, raiz1, raiz2, delta: Real; begin a := StrToFloat(Edit1.Text); b := StrToFloat(Edit2.Text); c := StrToFloat(Edit3.Text); delta := Power(b, 2) - 4 * a * c; raiz1 := (-(b) + (sqrt(delta))) / 2 * a; raiz1 := StrToFloat(Edit4.Text); raiz2 := (-(b) - (sqrt(delta))) / 2 * a; raiz2 := StrToFloat(Edit5.Text); end;
Responder
Clique aqui para fazer login e interagir na Comunidade :)