Last Updated:

Small calculator on pascal

Small calculator in pascal
 

Operation:

  • Addition
  • Subtraction
  • Multiplication
  • Division

The following operators are used for calculations:

  • +
  • /
  • *

The source can be run in the following programs: Pascal ABC.Net, Pascal ABC and TurboPascal.

Description

 

The entire program is built on the branching if statement. First, the program requests two numbers with which it will perform operations. After the program will offer 4 actions with these two numbers. You can select an action using the numbers from 1 to 4. Well, then it performs a calculation operation.

Well, also for convenience, comments have been added.

Program code

Var a, b, c, d, f, q: integer;
e:real;
begin

writeln('enter the first digit'); Enter the first number

readln(a); Reading the first number

writeln('enter the second digit'); Enter the second number

readln(b); Reading the second number

writeln('choose what you want to do with these numbers, 1 is addition, 2 is subtraction, 3 is multiplication, 4 is division'); Select an action

readln(q); Read an action

if (q=1) then// If you chose addition

writeln('your result', d); Gives the result of addition

if (q=2) then// If subtraction is selected

writeln('your result', f); Gives the result of subtraction

if (q=3) then// If multiplication is selected

writeln('your result', c); Gives the result of multiplication

if (q=4) then// If you selected division

writeln('your result', e); Gives the result of division

c:=a*b; multiplication of numbers

d:=a+b; addition of numbers

e:=a/b; division of numbers

f:=a-b; subtracting numbers

end.

Modification

The program can also be modified in every possible way, for example, you can replace the way the operation is selected. To do this, you must set the variable q to the string type. And instead of numbers, write operators in quotation marks - '+', '-', '/', '*'. And under the conditions of the branching operator, also replace the numbers with new notations. So it will be much more convenient.

You can also make the program work not only with integers, but also with fractional ones.
In addition to the current operators, you can also add an integer division operator - mod. And finding the remainder is div.

Again, the limitation here is just your imagination.

Such a simple calculator can be assembled in the pascal language. There are much more complex options, but such a source allows you to practice and study the cycles in more detail.