Answer to Question #249604 in C++ for nilson

Question #249604
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.

Since your program handles currency, make sure to use a data type that can store decimals with a precision to 2 decimals.





1
Expert's answer
2021-10-11T12:21:57-0400
#include <iostream>
#include <iomanip>
#include <string>


using namespace std;


int main()
{


	//Suppose that billingAmount is a double variable, which denotes 
	//the amount you need to pay to the department store. 
	double billingAmount=0;
	double paymentAmount=0;
	double credit=0;
	double paymentPercent=1;
	double penalty=0;
	cout<<"Enter the billing amount: ";
	cin>>billingAmount;
	cout<<"Enter the payment amount: ";
	cin>>paymentAmount;
	//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;
	double balance =billingAmount-paymentAmount; 


	//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. 
	if(balance!=0){
		paymentPercent=paymentAmount/billingAmount;
	}else{
		paymentPercent=1.0;
	}
	if(paymentPercent==1){
		credit=billingAmount*0.01;
		if(credit>10.00){
			credit=10.00;
		}
	}else if(paymentPercent>=0.50){
		penalty=balance*0.05;
	}else if(paymentPercent>=0.20 && paymentPercent<0.50){
		penalty=balance*0.10;
	}else{
		penalty=balance*0.20;
	}


	//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.
	if(penalty!=0){
		double unpaidBalance=billingAmount-paymentAmount+penalty;
		cout<<fixed<<"The penalty added to the next bill is: $"<<setprecision(2)<<penalty<<"\n";
		cout<<"The unpaid balance including the penalty is: $"<<setprecision(2)<<unpaidBalance<<"\n";
	}else{
		cout<<fixed<<"\nThank you for paying the full amount.\n";
		cout<<"Your will receive $"<<setprecision(2)<<credit<<" credit on your next bill\n";
	}
	cin>>credit;


	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS