educative.io

Code results in 1, but supposed to be .999991

I believe the following code may have been written erroneously. The comment states ‘Adding 0.001 for a thousand times’. But the code is actually ‘Adding 0.1 for ten times’ which returns 1. Great course on D by the way! Cheers! :slight_smile:

// Adding 0.001 for a thousand times:

    int counter = 1;

    while (counter <= 10) {

        result += 0.1;

        ++counter;

    }

Type your question above this line.

Course: https://www.educative.io/collection/10370001/5443442018615296
Lesson: https://www.educative.io/collection/page/10370001/5443442018615296/6324827021377536

Hello @Gary_Chike

Thank you for pointing out the typo. User feedback is very valuable for us and helps us to improve our content. The code snippet has been updated now according to the description.

Cheers!

1 Like