Georges Kayembe Georges Kayembe - 1 year ago 81
PHP Question

what's wrong with my while-loop php

Create a while-loop that subtracts 6.82 from the number 761 until the
number is between (not equal to) 23 and 33. Answer with the final result asa float, rounded to 2 decimals.

while (($f > 33)||($f < 23 )) {


I get the wrong answer, 27.68 instead of 31.26 on the book

Answer Source

I have checked your loop, and before last $f equals 33.5 because of $f++; so it will loop once more. It is like:

f = 50.96
f = 45.14
f = 39.32
f = 33.5 // still higher than 33 so do it once more
f = 27.68 // and now is lower, get out

It seems like $f++ is not necessary here.

You can check both codes:

PHP Compiler

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download