quarta-feira, 23 de janeiro de 2013

Calculadora em Delphi com Porcentagem


Variaveis Globais
  valor1, valor2, porcentagem:real;
  tipoconta:string;


botões numericos (aonde está o # você substitui pelo numero correspondente !)
 
    edit1.text:=edit1.text+'#';

-------- botão , --------

    edit1.text:=edit1.text+',';

-------- botão + --------

    tipoconta:='adição';
    valor1:=strtofloat(edit1.text);
    Edit1.Text:='';
    Label1.Caption:='+';

-------- botão - --------

    tipoconta:='subtração';
    valor1:=strtofloat(edit1.text);
    Edit1.Text:='';
    Label1.Caption:='-';

-------- botão x --------

    tipoconta:='multiplicação';
    valor1:=strtofloat(edit1.text);
    Edit1.Text:='';
    Label1.Caption:='X';

-------- botão / --------

    tipoconta:='divisão';
    valor1:=strtofloat(edit1.text);
    Edit1.Text:='';
    Label1.Caption:='/';

-------- botão = --------

    if tipoconta = 'adição' then
    begin
      valor2:=strtofloat(edit1.text);
      edit1.text:=floattostr(valor1+valor2);
   
    end;

    if tipoconta = 'subtração' then
    begin
      valor2:=strtofloat(edit1.text);
      edit1.text:=floattostr(valor1-valor2);
   
    end;

    if tipoconta = 'divisão' then
    begin
      valor2:=strtofloat(edit1.text);
      edit1.text:=floattostr(valor1/valor2);
   
    end;

    if tipoconta = 'multiplicação' then
    begin
      valor2:=strtofloat(edit1.text);
      valor1:= valor1*valor2;
      edit1.text:=floattostr(valor1);
   
    end;

-------- botão % --------

  if tipoconta = 'adição' then
   begin
      porcentagem:=strtofloat(edit1.text);
      porcentagem:=porcentagem/100;
      porcentagem:=porcentagem*valor1;
      edit1.text:=floattostr(valor1+porcentagem);
   end;

   if tipoconta = 'subtração' then
   begin
      porcentagem:=strtofloat(edit1.text);
      porcentagem:=porcentagem/100;
      porcentagem:=porcentagem*valor1;
      edit1.text:=floattostr(valor1-porcentagem);
   end;

-------- botão C --------

  edit1.text:='';
  valor1:=0;
  valor2:=0;
  tipoconta:='';
  Label1.Caption:='';

Nenhum comentário:

Postar um comentário