Little calculator

FlamingClaw 0 Tallied Votes 194 Views Share

This little calculator can +,-,/,*.Very simple,by FlamingClaw

Program Calculator;

Uses Crt;

Var  A,B:Real;
     M:Char;


Procedure GoAway;
   Begin
      Write('Wrong Data!');
      ReadLn;
      Halt;
   End;

Procedure Line;
   Var i:Byte;
   Begin
      For i:=0 To 30 Do Write('~');
      WriteLn;
   End;

Procedure WaitingForNumbers(Var wfn0,wfn2:Real;Var wfn1:Char);
   Begin
      Write('First number   :');
      {$I-}
      GotoXy(18,1);
      ReadLn(wfn0);
      Write('Operation      :');
      GotoXy(18,2);
      ReadLn(wfn1);
      Write('Second number  :');
      GotoXy(18,3);
      ReadLn(wfn2);
     {$I+}
      If (IoResult <> 0) Then GoAway;
   End;

{this function will evaluate}
Function OpChecker(OC0:Char;OC1,OC2:Real):Real;
   Begin
      Case (OC0) Of
         '+':OpChecker:=OC1+OC2;
         '-':OpChecker:=OC1-OC2;
         '/':OpChecker:=OC1/OC2;
         '*':OpChecker:=OC1*OC2
       Else GoAway;
       End;
   End;



Begin {main}
     ClrScr;
     WaitingForNumbers(A,B,M);
     Line;
     Write('Result         : ',OpChecker(M,A,B):2:2);
     WriteLn;
     ReadKey;
End. {main}

(*Created By FlamingClaw 2009.03.12*)