How does a program perform a calculation?
Programs often need to calculate totals, prices, scores, averages and many other values.
An arithmetic operator is a symbol or command that tells the computer which mathematical operation to perform.
Arithmetic operators are the calculation tools used by programs. They tell the computer whether to add, subtract, multiply, divide or find a remainder.
Programs often need to calculate totals, prices, scores, averages and many other values.
An arithmetic operator is a symbol or command that tells the computer which mathematical operation to perform.
+ adds, - subtracts, * multiplies and / divides.
Programming also uses DIV for whole-number division and MOD for the remainder after division.
Imagine a toolbox containing several calculator tools. One tool adds values, another subtracts them, and another finds what is left over after sharing.
You would not use a screwdriver when you need a hammer. In the same way, a programmer must choose the correct arithmetic operator for the job.
Each ticket costs 6. The program multiplies the ticket price by the number of tickets.
TicketPrice โ 6 NumberOfTickets โ 3 TotalCost โ TicketPrice * NumberOfTickets OUTPUT(TotalCost)
6 ร 3 = 18, so the value stored in TotalCost is 18.
Think of sharing 17 biscuits equally between groups of 5. You can make 3 complete groups, with 2 biscuits left over.
These two operators are frequently confused. Write a quick division fact before answering:
MOD is also useful for checking whether a number is odd or even. If Number MOD 2 = 0, the number is even.
MOD does not return the digits after the decimal point. It returns the whole-number remainder.