issue with a while loop
1 visualización (últimos 30 días)
Hey everybody, got a simple question for ya. Im making a function file to determine when it is safe to drive for a person who has been drinking. The value for hours in the output is wrong, but the formula works well outside of the loop. The answer should be around 2-3 hours, but the while loop consistently returns .28 hours. Heres my code
dpb el 3 de Ag. de 2014
Editada: dpb el 3 de Ag. de 2014
You've got the while operating until BAC<=0.08 by adjusting Hrs but one can take the expression
and solve for
What's wrong with your implementation that iterates where it isn't really needed is you're multiplying the difference/0.01 hr by the total hours every time instead of just the reduction/0.01 hr.
This isn't quite as accurate as the direct solution but given the inherent nature of the problem the correlation probably isn't accurate to a tenth of an hour, either...