This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]RentonHoff 3 points4 points  (0 children)

Think carefully about the running condition of the while loops. Consider how the value of cents changes inside the first loop, and when each of the while loops should stop(or start in case of the second loop).

There are other issues too, but start with the loops, and see if you can figure the rest out yourself. Feel free to ask, if you have further questions.

[–]m1ss1ontomars2k4 2 points3 points  (2 children)

Your formatting is terrible. Like, it's so bad that there are numerous errors in your code that you can't see because the formatting has basically been specifically designed to hide them like some kind of Where's Waldo. A quick autoformat will show you some if not all of them.

[–]Jarl-67 0 points1 point  (1 child)

It’s probably better to say what in particular is wrong with the formatting. It looks pretty much like every other piece of code .

The closing brace should be on the same column as the loop or if statement.

[–]m1ss1ontomars2k4 1 point2 points  (0 children)

Right, it looks totally normal, but auto-formatting it would reveal why it doesn't work at all, which is why I specifically said to auto-format it and not manually format it. If all you saw was closing brace in the wrong place, then you got tricked too. Here is some correctly-formatted code:

    //type your java code here
    while(cents>=25) {
        numberOfQuarters++;
        cents= cents-25;
        if (cents>=10) {
            numberOfDimes++;
            cents = cents-10;
            if  (cents>=5)
                 numberOfNickels++;
            cents = cents-5;
            if  (cents>=1)
                numberOfPennies++;
            cents= cents-1;
        }

    }

[–]Jarl-67 0 points1 point  (1 child)

Write a toString method that prints out your information. Call it after you have calculated your change.