hola buenas tardes .. soy nuevo en este foro... eh estado trabajando con delphi en crear una carculadora hasta ahora voy bien, las operaciones basicas como suma, resta, division y multiplicacion me compilan bien
por ejemplo si yo hago 2+2= 4 me funciona pero quiero realizar una operacion convinada como "2+3-4*2"y cuando aprete la tecla "=" me tire el resultado de dicha operación, es decir que yo cuando realice "2+3" en el visor me muestre "5" al apretar la tecla - y al ingresar "4" y de nuevo al apretar la tecla * me muestre el resultado "1" y de nuevo ingrese "2" y al apretar esta vez la tecla "=" me salga el resultado que seria "2"
hay viene mi problema que no logro realizar esta tarea ; si alguien tiene alguna solución, o pueda guiarme para realizar este trabajo se los agradecería mucho aquí les dejo mi programa
Código Delphi
[-]type
TForm2 = class(TForm)
visor: TLabel;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button5: TButton;
Button4: TButton;
Button6: TButton;
Button7: TButton;
Button8: TButton;
Button9: TButton;
ButtonSuma: TButton;
ButtonResta: TButton;
ButtonIgual: TButton;
ButtonProducto: TButton;
ButtonDivision: TButton;
button0: TButton;
procedure button0Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure Button8Click(Sender: TObject);
procedure Button9Click(Sender: TObject);
procedure ButtonSumaClick(Sender: TObject);
procedure ButtonRestaClick(Sender: TObject);
procedure ButtonProductoClick(Sender: TObject);
procedure ButtonDivisionClick(Sender: TObject);
procedure ButtonIgualClick(Sender: TObject);
private
op: string;
op2: real;
op1:real;
result:string;
public
end;
const
Pi = 3.14;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.button0Click(Sender: TObject);
begin
if (sender is tbutton) and (visor.Caption ='0') then
visor.Caption:= visor.Caption+(sender as tbutton).Caption
else
visor.Caption:= visor.Caption+(sender as tbutton).Caption
end;
procedure TForm2.Button1Click(Sender: TObject);
begin
if (sender is tbutton) and (visor.Caption ='1') then
visor.Caption:= visor.Caption+(sender as tbutton).Caption
else
visor.Caption:= visor.Caption+(sender as tbutton).Caption
end;
procedure TForm2.Button2Click(Sender: TObject);
begin;
if (sender is tbutton) and (visor.Caption ='2') then
visor.Caption:= visor.Caption+(sender as tbutton).Caption
else
visor.Caption:= visor.Caption+(sender as tbutton).Caption
end;
procedure TForm2.Button3Click(Sender: TObject);
begin
if (sender is tbutton) and (visor.Caption ='3') then
visor.Caption:= visor.Caption+(sender as tbutton).Caption
else
visor.Caption:= visor.Caption+(sender as tbutton).Caption
end;
procedure TForm2.Button4Click(Sender: TObject);
begin
if (sender is tbutton) and (visor.Caption ='4') then
visor.Caption:= visor.Caption+(sender as tbutton).Caption
else
visor.Caption:= visor.Caption+(sender as tbutton).Caption
end;
procedure TForm2.Button5Click(Sender: TObject);
begin
if (sender is tbutton) and (visor.Caption ='5') then
visor.Caption:= visor.Caption+(sender as tbutton).Caption
else
visor.Caption:= visor.Caption+(sender as tbutton).Caption
end;
procedure TForm2.Button6Click(Sender: TObject);
begin
if (sender is tbutton) and (visor.Caption ='6') then
visor.Caption:= visor.Caption+(sender as tbutton).Caption
else
visor.Caption:= visor.Caption+(sender as tbutton).Caption
end;
procedure TForm2.Button7Click(Sender: TObject);
begin
if (sender is tbutton) and (visor.Caption ='7') then
visor.Caption:= visor.Caption+(sender as tbutton).Caption
else
visor.Caption:= visor.Caption+(sender as tbutton).Caption
end;
procedure TForm2.Button8Click(Sender: TObject);
begin
if (sender is tbutton) and (visor.Caption ='8') then
visor.Caption:= visor.Caption+(sender as tbutton).Caption
else
visor.Caption:= visor.Caption+(sender as tbutton).Caption
end;
procedure TForm2.Button9Click(Sender: TObject);
begin
if (sender is tbutton) and (visor.Caption ='9') then
visor.Caption:= visor.Caption+(sender as tbutton).Caption
else
visor.Caption:= visor.Caption+(sender as tbutton).Caption
end;
procedure TForm2.ButtonDivisionClick(Sender: TObject);
begin
op2:= StrToFloat ( visor.Caption);
op:= '4';
visor.Caption:=''
end;
procedure TForm2.ButtonProductoClick(Sender: TObject);
begin
op2:= StrToFloat ( visor.Caption);
op:= '3';
visor.Caption:=''
end;
procedure TForm2.ButtonRestaClick(Sender: TObject);
begin
op2:= StrToFloat ( visor.Caption);
op:= '2';
visor.Caption:='';
end;
procedure TForm2.ButtonSumaClick(Sender: TObject);
begin
op2:= StrToFloat ( visor.Caption);
op:= '1';
visor.Caption:=''
end;
procedure TForm2.ButtonIgualClick(Sender: TObject);
begin
op1:= strtofloat(visor.Caption);
if (op='1') then
begin
result:= floattostr(op2+op1);
end
else
if (op='2') then
begin
result:= floattostr(op2-op1);
end
else
if (op='3') then
begin
result:= floattostr(op2*op1);
end
else
if (op='4') then
begin
if (op1<>0) then
begin
result:= floattostr(op2/op1);
end
else
showmessage('Divisor 0')
end;
visor.Caption:= result;
end;
end.