# Math error in App Lab

#1

A student is making a shopping app in AppLab for her Create Task. Her program code is correct for adding two values however the result is not what you would expect. If she chooses the beach ball (\$4.99) and adds anything to it, she gets a crazy amount of decimal places. Two numbers with two decimal places that are added together should not result in as many decimal places as shown in the console log.

Any ideas?

#2

This is a great opportunity for you to refer back to the Code.org unit on representing and encoding numbers. Because there are an infinite number of values between any two integer values and our software is forced to use a fixed number of bits to represent numbers, we canâ€™t possibly come close to encoding every possible decimal number. This studentâ€™s code demonstrates the loss of precision that is a side effect of representing fractional numbers in binary.

Ok, now how to fix it?
One easy option is to have the student change the prices to be integer values.
Another option is store all of the prices in cents and then convert to dollars and cents when displaying the value in the app. This can be a challenging but satisfying problem for students to solve!

#3

Thanks, @Mitch - I learned something new.

Too bad @awright that youâ€™re not allowed to share with the student @Mitchâ€™s options on how to fix it (as far as I understand the rules - unless itâ€™s a section sheâ€™s not doing the Written Response part about), but the positive side about that is this definitely gives her something to talk about for Written Response 2b (incremental and iterative program development - describe a difficulty). (Although hm, we canâ€™t tell her that either huhâ€¦ )

Thanks for bringing up the interesting problem!

Frank

#4

Or can I? It is a technical problem â€“ and we are allowed to help with that and with directions. So telling her that it is a problem with precision of the language that AppLab uses doesnâ€™t actually do anything outside the â€śrulesâ€ť does it?

#5

I agree that itâ€™s okay to explain why itâ€™s doing what itâ€™s doing, but Iâ€™m less sure about providing possible solutions. Iâ€™m not 100% certain though and Iâ€™m not the College Board.

#6

I really wish the College Board would be more explicit with the teacher instructions because a lot is definitely open to interpretation. I donâ€™t see this as a technical problem because I read that to mean something technology related that is preventing the student from completing the work, like problems accessing the CB website or instruction is needed in how to capture video. Although, it is arguable that under the guideline of â€śTeachers may continue whole class teaching of course content and skills during non-designated time to complete the performance taskâ€ť, you would be able to teach the class about floating point precision errors and how to avoid them.

The answer to the question is unclear to me but I would err on the safe side and explain that there is nothing in the grading guidelines that takes off points for code that doesnâ€™t work as expected. Itâ€™s unfortunate that perhaps the best thing to do is to recommend submitting buggy code but thatâ€™s all that I can assume that weâ€™re supposed to do.