terça-feira, março 15, 2011

LP - Calculadora com Procedures - Pascal

Program Pzim ;
var opcao:integer;

Procedure menu;
   begin
    writeln ('=============================');
    writeln ('||   ___________________   ||');
    writeln ('||  |                   |  ||');
    writeln ('||  | 1 - soma          |  ||');
    writeln ('||  |___________________|  ||');
    writeln ('||   ___________________   ||');
    writeln ('||  |                   |  ||');
    writeln ('||  | 2 - subtração     |  ||');
    writeln ('||  |___________________|  ||');
    writeln ('||   ___________________   ||');
    writeln ('||  |                   |  ||');
    writeln ('||  | 3 - divisão       |  ||');
    writeln ('||  |___________________|  ||');
    writeln ('||   ___________________   ||');
    writeln ('||  |                   |  ||');
    writeln ('||  | 4 - multiplicação |  ||');
    writeln ('||  |___________________|  ||');
    writeln ('||   ___________________   ||');
    writeln ('||  |                   |  ||');
    writeln ('||  | 5 - sair          |  ||');
    writeln ('||  |___________________|  ||');
    writeln ('||                         ||');                     
    writeln ('== Digite sua opção  [   ] ==');                     
   end;

Procedure soma;
    var n1,n2,soma:real;
    begin
        Write('Digite o Primeiro número...: ');
        Readln(n1);
        Write('Digite o Segundo número....: ');
        Readln(n2);
        soma:=n1+n2;
        Writeln('A soma dos dois números acima é ',soma);
        readkey;
        clrscr;       
     end;
  
Procedure subtracao;
    var n1,n2,subtracao:real;
    begin
        Write('Digite o Primeiro número...: ');
        Readln(n1);
        Write('Digite o Segundo número....: ');
        Readln(n2);
        subtracao:=n1-n2;
        Writeln('A subtração dos dois números acima é ',subtracao);
        readkey;
        clrscr;       
     end;
  
Procedure multiplicacao;
    var n1,n2,multiplicacao:real;
    begin
        Write('Digite o Primeiro número...: ');
        Readln(n1);
        Write('Digite o Segundo número....: ');
        Readln(n2);
        multiplicacao:=n1*n2;
        Writeln('A multiplicação dos dois números acima é ',multiplicacao);
        readkey;
        clrscr;       
     end;

Procedure divisao;
    var n1,n2,divisao:real;
    begin
        Write('Digite o Primeiro número...: ');
        Readln(n1);
        Write('Digite o Segundo número....: ');
        Readln(n2);
        divisao:=n1/n2;
        Writeln('A divisão dos dois números acima é ',divisao);
        readkey;
        clrscr;
     end;
  
 Begin
    repeat
        begin
            menu;
           
            gotoxy(24,23);    read(opcao);
           
            if (opcao=1) then
                    soma;
                   
            if (opcao=2) then
                    subtracao;
                   
            if (opcao=3) then
                    divisao;
                   
            if (opcao=4) then
                    multiplicacao;
                   
            if ((opcao <> 1) and (opcao <> 2) and (opcao <> 3) and (opcao <> 4) and (opcao <> 5)) Then
                writeln('Esta opção não exite ooooooo Espertão...');
        end;
    until (opcao=5);
    Writeln ('saindo da calculadora');
    readkey;
 End.

Nenhum comentário:

Postar um comentário