Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!

Jessica Curtner
Greenhorn
Posts: 2
hello, I am a little stuck on a homework assignment, "Pennies for Pay" basically i have to write a program using a loop that will calculate a persons earnings over a period of time. The person will earn a penny the first day, 2 pennies the second day and continues to double each day and show a table displaying the salary for each day and total pay at the end of the period... My problem is the output i am getting is different than it should be see below:

run:
How many days did you work?
5
Days Worked Amount Paid
--------------------------------------------
1 0.02 <--This should be 1
2 0.04
3 0.08
4 0.16
5 0.32
\$1.62
BUILD SUCCESSFUL (total time: 3 seconds)

Albareto McKenzie
Ranch Hand
Posts: 299
I edit because my answer was not correct.

To see why the result in the first case is 0.02 instead of 0.01 you have to check what are you doing in line 45. What value has currentpay in the first loop? and what value are you asigning? maybe and aditional check is neccesary there ;)

Campbell Ritchie
Sheriff
Posts: 48976
60
I can see what has happened, but you will need additional information to see it yourself.

Insert the following line in your code, after line 44 and before line 45:and this after the present line 47:Note the two lines are very similar

Why are you using DecimalFormat rather than the printf methods? What will happen if somebody enters 0 as number of days worked?

Albareto McKenzie
Ranch Hand
Posts: 299
Ey Campbell, you are fast, I was editting my answer

If someone inserts 0 there is a check at line 35

Campbell Ritchie
Sheriff
Posts: 48976
60
Albareto McKenzie wrote:Ey Campbell, you are fast, I was editting my answer

If someone inserts 0 there is a check at line 35
Speed? It's all practice, practice

But don't tell Jessica what the check at line 35 actually does

Albareto McKenzie
Ranch Hand
Posts: 299
She will find it soon