While Loop Mini-Labs
Required Knowledge
This labs require you to write program code to use the following topics. Tutorials for available topics have been linked.
Mini-Lab 1: ATM Withdrawals
Write program code that will ask the user for an amount to withdraw. Keep prompting if the requested amount exceeds their account balance or is not a positive multiple of $20.
Program Requirements
- Use only
while
loops to complete this lab.
- Create an account balance variable and set it to $500.
- Output a receipt that includes the amount that was withdrawn from the account and how much is still available.
- Challenge 1: Add messages for why their withdrawal amount was not accepted.
- if the request exceeds the account balance, print "Insufficient Funds! Please enter a value less than accountBalance." (
accountBalance
is the variable that stores the users account balance).
- if the request is not a multiple of $20, print "Please enter a withdrawal amount that is a multiple of $20 and less than your account balance of accountBalance." (
accountBalance
is the variable that stores the users account balance).
- Challenge 2a: After a withdrawal was successful, ask the user if they would like to make a second withdrawal and repeat the withdrawal process.
- Challenge 2b: Modify Challenge 2a to repeatedly ask the user if they would like to make a second withdrawal until they answer no.
- Challenge 2c: Modify Challenge 2b to only ask if they want to make another withdrawal if they have an account balance greater than 0.
Write program code to continuously ask the customer to enter the prices of items to be purchased, stopping only when they type "done". Then, display the total.
Program Requirements
- Use only
while
loops to complete this lab.
- You can assume that the user will either enter "done" or a
double
amount for the price.
- Only parse the input if it is not equal to "done".
- Challenge 1: Keep track of the number of items that were entered as well. Be sure not to include when the user enters "done" as an item. Add the number of items being purchased to the display.
Mini-Lab 3: Employee Time Entry
Write a program for an employee to enter their work hours for each day of the week. If the input is not between 0 and 24 (inclusively), prompt again, until all 7 days are valid. Then, display the total amount of time worked during the week.
Program requirements
- Use only
while
loops to complete this lab.
- If an employee doesn't work on one of the days, they should enter 0 when prompted.
- Challenge 1: If you haven't done so already, modify the code to include a prompt that asks for the number of hours for a specific day numbered 1 to 7. For example:
Enter your hours for Day 1
- Challenge 2: If the employee entered a number of hours more than 8 and less than or equal to 24 for a given day, notify them that they are eligible for overtime pay for that day. Keep track of overtime hours separate from regular hours.
- Challenge 3: Calculate the employees weekly pay as follows:
- Regular hours are paid at $14 per hour.
- Overtime pay is calculated as follows:
- Daily overtime pay is paid at $16 per hour, unless the total number of regular hours equals 40 hours. In that case, overtime is paid at $21 per hour.