Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem 1 : (definite loop) Write a program that calculates how much a person would earn over a period of time if his or her

Problem 1 : (definite loop) 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 ask the user for the number of days. Use a loop to validate that you worked at least 1 day. Display a table showing the day number, the daily salary, and the total paid for that number of days. 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. Make sure you use an accumulator DO NOT create a formula to determine the amount! Sample program output: (Test Case 1) Enter the number of days: -3 You must work at least 1 day! Please re-enter: -4 You must work at least 1 day! Please re-enter: 4 Day Daily Pay Total 1 0.01 0.01 2 0.02 0.03 3 0.04 0.07 4 0.08 0.15 Total earned in 4 days is $ 0.15 Coded by your name Test Case 2: 15 days Test Case 3: 30 days Problem 2 (Indefinite Loop): This is a modification of problem 3 from your last assignment. Instead of specifying the number of years your money will be on deposit with the bank, you want to know how many years it will take to become a millionaire. Assume you open a savings account with a certain balance. The input is the starting balance, and the interest rate on the account (as a percent). You should use loops to validate that the balance and interest rate are greater than zero. Assume you never withdraw any of the money, and each year you gain interest on the current balance. Your program will determine the number of years it will take for your balance to equal or exceed one million dollars. You will need to modify your loop because you do not know how many years of interest will be calculated. DO NOT USE A FORMULA TO DETERMINE THE ANSWER. You MUST use an accumulator. This is an INDEFINITE loop problem, think about how to structure your loop before you start. You may need to output the balance each year (like the previous problem) during testing to make sure your algorithm is correct. Sample output Enter starting balance of account: -900000 Invalid, re-enter: 900000 Enter interest rate (percentage): -10 Invalid, re-enter: 10 At 10.00% interest rate, you will become a millionaire in 2 years! Coded by yourname Other test cases Test case 2: $1000 at 8% interest Test case 3: $10000 at 5.5% interest? Test case 4: $50000 at 7.5% interest?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions