Wednesday, November 25, 2015

Simple Math Calculator in Pascal

A simple math calculator that I wrote in Pascal programming language that will ask the user to give two numbers and then the user will select the operand either plus, subtract, multiplication and division mathematical operations. I am using Turbo Pascal 5.5 For DOS as my pascal compiler in this sample program.

If you  have some questions please send me an email at jake.r.pomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.




Sample Program Output

Program Listing


Program Basic_Calculator;
Uses Crt;

Var

 Operator   : Char;
 Opt1,Opt2  : Integer;
 Sum,Subtract, Multiply: Integer;
 Divide     : Integer;
 Result     : Integer;

Begin

  clrscr;
  Opt1 := 0; Opt2 := 0;

  write('Simple Math Calculator');
  writeln; writeln;
  write('Enter Two Numbers : ');
  readln(Opt1,Opt2);
  write('Select Operators +,-,* and / : ');
  readln(Operator);
  if (Operator = '+') then
    Begin
      Sum := (Opt1 + Opt2);
      Result := Sum;
    End


   else if (Operator = '-') then
    Begin
      Subtract := (Opt1 - Opt2);
      Result := Subtract;

    End

   else if (Operator = '*') then
    Begin
      Multiply := (Opt1 * Opt2);
      Result := Multiply;

    End

   else if (Operator = '/') then
    Begin
      Divide := (Opt1 DIV Opt2);
      Result := Divide;

    End;


  writeln;
  writeln;
  Write('The result is ' ,Result,'.');
  readln;

End.







No comments:

Post a Comment