Question: Write a program that calculates how much a person would earn over a period of time if his or her salary is one penny the

Write a program that calculates how much 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 proceed as follows:

Ask the user for the number of days worked, and allow them to enter it. You may assume this will be an integer

A valid entry must be 1 or more days, so whenever the user enters a valid that is not positive (1 or more), print an error message and make them re-enter until they give a valid value.

Display a table showing how much the salary was for each day. You can use the \t character to help print neat columns.

Display the total pay at the end of the period

We will only test your code with a relatively small number of days worked (This is because the earnings get WAY too big after a certain point... maybe that's not such a bad thing though - ha). To help account for larger earnings (if you want), you can declare your variable which stores the amount earned as a long double.

All monetary outputs should be in dollar and cents notation (not just number of pennies), in this format: $ D.cc , where D is the number of dollars, and cc is the cents (always two digits). Examples:

 Valid: $ 1.34 , $ 0.05 , $ 123.45 

Sample Runs

(user input is underlined, to distinguish it from output)

Sample Run 1

Please enter the number of days worked: -1 Invalid number of days. Try again Please enter the number of days worked: 0 Invalid number of days. Try again Please enter the number of days worked: 5 Day Amount Earned ------------------------------------------- 1 $ 0.01 2 $ 0.02 3 $ 0.04 4 $ 0.08 5 $ 0.16 Total earnings: $ 0.31 

Sample Run 2

Please enter the number of days worked: 18 Day Amount Earned ------------------------------------------- 1 $ 0.01 2 $ 0.02 3 $ 0.04 4 $ 0.08 5 $ 0.16 6 $ 0.32 7 $ 0.64 8 $ 1.28 9 $ 2.56 10 $ 5.12 11 $ 10.24 12 $ 20.48 13 $ 40.96 14 $ 81.92 15 $ 163.84 16 $ 327.68 17 $ 655.36 18 $ 1310.72 Total earnings: $ 2621.43

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!