Lab 3 - Flow Control and Input Validation

Due: Midnight on the day of the lab

Write your code in a source file called lab3.cpp. Email the source code to my Sleipnir account when you have completed the assignment.

Scenario: This program will track payments for a personal interest-free loan. A minimum payment of 4% is required.

The program will be based around the while loop. You will also be using an if-else statement with a complex Boolean expression to validate that the monthly payment is greater than or equal to the minimum payment and less than or equal to the loan balance.

The program will prompt for the initial loan balance BEFORE entering the while loop. It will then enter the while loop to process the monthly payments. This loop will first calculate the minimum payment and prompt the user for the monthly payment. It then validates the payment using the if-else statement described above. If the payment is valid, the payment is deducted from the balance. Otherwise, an error message is printed to the screen using cout.

The pseudocode is as follows:

prompt the user for the loan balance
read in the balance
while the balance is greater than 0
  calculate the minimum payment (4% of balance)
  prompt the user for their monthly payment
  read in the monthly payment
  if the payment is >= minimum payment and the payment is <= balance
    update the balance by subtracting the payment
  else
    print error message "Incorrect payment. Minimum is <minimum> and maximum is <balance>" 
      (replace <minimum> with the minimum payment you calculated and <balance> with the current balance)
  end-if
end-while
print "Loan is paid off" to the screen
To simplify calculations, use integers for the balance, interest, minimum payment and monthly payment. While doubles would be more realistic, we have not yet learned how to round doubles to just two decimal places of precision.

Your output should resemble the following. User input is show as blue text.

Enter loan balance: 500

Balance is $500. Minimum payment is $20.
Enter payment amount: 50

Balance is $450. Minimum payment is $18.
Enter payment amount: 5
Incorrect payment. Minimum is $18 and maximum is $450.

Balance is $450. Minimum payment is $18.
Enter payment amount: 100

Balance is $350. Minimum payment is $14.
Enter payment amount: 500
Incorrect payment. Minimum is $14 and maximum is $350.

Balance is $350. Minimum payment is $14.
Enter payment amount: 350

Loan is paid off.