Write Algorithm for Billing Amount to Compute Credit or Penalty

Problem Statement:

Suppose that billingAmount is a double variable, which denotes the amount you need to pay to the department store. If you pay the full amount, you get $10.00 or 1% of the billingAmount, whichever is smaller, as a credit on your next bill; If you pay at least 50% of the billingAmount, the penalty is 5% of the balance; If you pay at least 20% of the billingAmount and less than 50% of the billingAmount, the penalty is 10% of the balance; otherwise the penalty is 20% of the balance. Design an algorithm that prompts the user to enter the billing amount and the desired payment. The algorithm then calculates and outputs the credit or the remaining balance. If the amount is not paid in full, the algorithm should also output the penalty amount. 


Possible Solution:

Begin

Declare billingAmount as Real
Declare paidAmount as Real
Declare credit as Real
Declare penalty as Real
Declare amount as Real
Declare percent as Real

Set credit = 0
Set penalty = 0
Set amount = 0

Output "Enter bill amount $"
Input billingAmount
Output "Enter paid amount $"
Input paidAmount

If billingAmount = paidAmount Then
	Set amount = 0.001 * billingAmount
	If amount < 10 Then
		Set credit = amount
	Else
		Set credit = 10
	End If
Else
	Set amount = billingAmount - paidAmount
	Set percent = (paidAmount / billingAmount) * 100
	If percent >= 50 Then
		Set penalty = 0.005 * amount
	Else If paidAmount between 20 to 49 Then
		Set penalty = 0.01 * amount
	Else
		Set penalty = 0.02 * amount
	End If
End If

If 0 < credit Then
	Output "Credits $" credit
Else If 0 < penalty Then
	Output "Balance $" amount
	Output "Penalty $" penalty
End IF

Exit

Comments

Popular posts from this blog