I have asked to make a function that have two parameters, start number and the end number and should return the count of all numbers except numbers with a 5 in it. The start and the end number are both inclusive!
The start number will always be smaller than the end number. Both numbers can be also negative! The end number may be a very big integer value like 10^9
any suggestions?
You have a couple of problems in you current code. The first is as pointed out, just dividing a number by 10 causes the number to start having decimal places. This means it will almost always be > 0.
SO you could change that to use
floorto round it down...The other problem you have is in your comparison -
With or (
||) as soon as it finds a true value, it stops checking the rest of the condition (as the result will still be true), so theisDigitPresent()will not be called if$numis != 5 (which is most of the time.) So this should be shortened toThere are all sorts of alternatives to this, but based on what you doing you could use...