Monday, October 3, 2011

Challenge 018’s Solution

Potential Fixes 1−4 correctly output “2.6”, while Potential Fix 5 incorrectly outputs “2.0”. This is due to how each Potential Fix is written. Potential Fix 1 writes “(double)” before the number 13, making 13 into the double value 13.0. When a double value (13.0) is divided over an int value (5), the result must be a double value (2.6). Next, in Potential Fix 2, the term “(double)” is written before the number 5, making 5 into the double value 5.0; therefore, the result is the double value 2.6. Third, Potential Fix 3 writes “13.0” in place of “13”. Since 13.0 is, by itself, a double value, the result is again 2.6. After that, Potential Fix 4 does something similar, writing “5.0” in place of “5”. 5.0 is a double value; the result is 2.6. Finally, there is Potential Fix 5, which doesn’t work. While this solution does write “(double)” before the equation, it mistakenly uses extra parentheses, writing “(13 / 5)”. This causes the function 13 ÷ 5 to be performed first, but, since both numbers are written as int values, the result is 2. This number is what then gets converted into the double value 2.0, which is output’d in the end.
 
−Phoenix

1 comment:

  1. Most excellent, Pheonix; 25 XPs for the completion of this challenge.

    ReplyDelete