FAQs on the exercise Mathematical Assignment Operators
There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.
If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply () below!
Agree with a comment or answer? Like () to up-vote the contribution!
we add two, then we multiple by two, so now in essence we have added 4 to the original number, now we subtract two, and divide by two, so the number is one higher then the number we started out with
sort of like doing plus two and then minus one, but then slightly different due to the multiplication.
or +4 and -2, which essentially happens here. The 2 we added gets multiplied to become 4. Its clever little trick, difficult to explain.
Yes, I meant by this code! I got it by doing step-by-step execution.
Here’s what I did:
<?php
// Write your code below:
$answer=4;
$my_num=2;
$answer=$my_num;#2
$answer+=2;#4
$answer*=2;#4*2=8
$answer-=2;#8-2=6
$answer/=2;#6/2=3
#part 1: now the answer is 3
$answer-=$my_num; # part 2: original values won't change, so 4-2=2
echo $answer; #part 1- part 2
Hope that’s clear how the execution was done. If by chance I got it wrong, do correct me! : )
Since your number is larger than the maximum integer value allowed in php, so the number is converted to float. But, floats can only be precise to a specific number of digits. Your number as a float will not have the same number of digits as the original number. To confirm this, try the following
So, adding/subtracting small numbers such as 1 or 2 (see zunaid.hassan’s post above for a breakdown of the steps) from such numbers isn’t going to show up because of the precision.
Try running the following:
<?php
$my_num1 = 2367823678289863829823643781;
$my_num2 = $my_num1 + 100;
echo $my_num1;
echo "\n";
echo $my_num2;
echo "\n";
echo $my_num1 - $my_num2; // The answer will be 0