At their core, computers are basically fancy calculators. So it’s a good thing to learn how to perform basic mathematical operations early on in your language development.
Addition and subtraction work just as you would expect them to.
a = 2 + 3 will store
5 in the variable
a. You can also use these variables as part of the math (or all of it).
int a = 2; int b = 3; int c = a + b;
These same foundational principles of mathematics hold true for subtraction, multiplication, and division.
Now we can add a little flavor to our variable knowledge. The program on the right already has the declaration of the variables and some values set, as well as the output to display the final results.
Your task is to modify the values stored in the variables using basic mathematical symbols given any changes.
It was a good week, you sold 200 more books! Update the
Now that you have the updated book sale counts, calculate the
Your publisher takes half of the total sales as part of their cut. Update your
totalSalesValue accordingly (you can do this with multiplication or division in the real world, but for practice, please use division).