1. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Mar 2013
Posts
18
Rep Power
0

#### Pennies Calculator

Hey Ya'll.

Write a program that calculates the amount a person would earn over a period of time if his or her salary is one penny the first day, two pennies the second day, and continues to double each day. The program should display a table showing the salary for each day, and then show the total pay at the end of the period. The output should be displayed in a dollar amount, not the number of pennies.

So far I got this:

int days;
double pay = 0, salary = 1;
int i;

System.out.println("How many days did you work? ");
days = keyboard.nextInt();

if(days >=1)
days = days;
else
System.out.println("Please enter a valid number greater than or equal to 1. ");

for(i = 1; i <= days; i++)
{
pay += salary;
salary *= 2;

System.out.println("You worked " + days + " day(s) and made " + salary + " cents.");
}

//

The problem with this is that, it displays xx.0 cents. I need it to be in dollar form. Also the days = the inputed days, it doesn't show day 1, day 2, day 3 ... etc.

EDIT: Here's the output

How many days did you work?
4
You worked 4 day(s) and made 2.0 cents.
You worked 4 day(s) and made 4.0 cents.
You worked 4 day(s) and made 8.0 cents.
You worked 4 day(s) and made 16.0 cents.
2. Please copy the program's output and paste it here.
Also please edit the post and wrap the code in code tags to preserve formatting.
3. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Mar 2013
Posts
18
Rep Power
0
Originally Posted by NormR
Please copy the program's output and paste it here.
Also please edit the post and wrap the code in code tags to preserve formatting.
How many days did you work?
4
You worked 4 day(s) and made 2.0 cents.
You worked 4 day(s) and made 4.0 cents.
You worked 4 day(s) and made 8.0 cents.
You worked 4 day(s) and made 16.0 cents.
4. Also please edit the post and wrap the code in code tags to preserve formatting.

What do you want to see different about the output? What variable has that value in it?
The variable: days has the value 4. What variable has the value you want to see?
5. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Mar 2013
Posts
18
Rep Power
0
Originally Posted by NormR
Also please edit the post and wrap the code in code tags to preserve formatting.

What do you want to see different about the output? What variable has that value in it?
The variable: days has the value 4. What variable has the value you want to see?
I want it to display the total number of penny on the inputed days, such as 4 days or 5 days.
6. Can you post what you want the output to look like?
7. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Mar 2013
Posts
18
Rep Power
0
Originally Posted by NormR
Can you post what you want the output to look like?
How many days did you work?
4
You worked 1 day(s) and made 2.0 cents.
You worked 2 day(s) and made 4.0 cents.
You worked 3 day(s) and made 8.0 cents.
You worked 4 day(s) and made 16.0 cents.
8. Originally Posted by onion4ya
How many days did you work?
4
You worked 1 day(s) and made 2.0 cents.
You worked 2 day(s) and made 4.0 cents.
You worked 3 day(s) and made 8.0 cents.
You worked 4 day(s) and made 16.0 cents.
Note that one simple change inside your for loop will fix the day issue.

Are you allowed to use the DecimalFormat class?
9. Did you miss this:

What do you want to see different about the current output and the desired output?
The variable: days has the value 4.
What variable has the value you want to see?
10. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Mar 2013
Posts
18
Rep Power
0
Originally Posted by bullet
Note that one simple change inside your for loop will fix the day issue.

Are you allowed to use the DecimalFormat class?
I'm not sure what that is yet. I'm assuming we can use the printf function or divide the salary by 100 to get it formated into this form: \$0.00
11. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Mar 2013
Posts
18
Rep Power
0
Originally Posted by NormR
Did you miss this:

What do you want to see different about the current output and the desired output?
The variable: days has the value 4.
What variable has the value you want to see?
I want the number of days and amount of money earned on that day. And in the end, I want to see the total amount of money earned in dollar format, not penny format.
12. What is wrong with the current output from the program?

Do you know how to add the contents of one variable to another?
Use that technique to sum up each days amount in a total variable.
Then print that amount after the data for each day has been printed.
13. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Mar 2013
Posts
18
Rep Power
0
Originally Posted by NormR
What is wrong with the current output from the program?

Do you know how to add the contents of one variable to another?
Use that technique to sum up each days amount in a total variable.
Then print that amount after the data for each day has been printed.
I don't know how to add up the loops and print out a total based on X number of days.
14. What variable contains the value that you want to add up?

Define a new variable before the loop
add the value you want to sum up to that variable inside the loop
print the contents of that variable after the end of the loop