Answer to Question #240402 in C++ for Bryce

Question #240402

A customer makes a purchase at the store. The tax rate is 8% on all purchases


except groceries. The store offers a 5% discount to seniors 60 and over. You


should ask the user three questions: what they have bought (use a menu


displaying bread, milk, or soap), what the purchase price is, and how old they are.


Your goal is to print a formatted invoice with the following line items: price, tax,


discount, and total. The discount should only be printed if applicable.


You should test your program with 5 data sets: with and without tax and with and


without the senior discount. The fifth data set makes an invalid choice of the


menu item, in which case your program should not ask any more questions and


output an error message.



1
Expert's answer
2021-09-22T03:47:57-0400
using namespace std;




/*
	A customer makes a purchase at the store. The tax rate is 8% on all purchases except groceries. The store offers a 5% discount to seniors 60 and over. You
	should ask the user three questions: what they have bought (use a menu displaying bread, milk, or soap), what the purchase price is, and how old they are.
	Your goal is to print a formatted invoice with the following line items: price, tax, discount, and total. The discount should only be printed if applicable.
	You should test your program with 5 data sets: with and without tax and with and without the senior discount. The fifth data set makes an invalid choice of the
	menu item, in which case your program should not ask any more questions and output an error message.
*/


#define BREAD	0
#define MILK	1
#define SOAP	2
#define MUG		3
#define PLATE	4


#define NON_GROC	0
#define GROC	1


#define NO_OF_ITEMS	5
#define AGE_LIM	60


int main()
{
	int ItemNo,Qty[NO_OF_ITEMS],Class[NO_OF_ITEMS],Flag=NO_OF_ITEMS+1,Age,n;
	string Items[NO_OF_ITEMS] = {"Bread","Milk","Soap","Mugs","Plates"};
	float Price[NO_OF_ITEMS],Tax[NO_OF_ITEMS],Total,Net,Discount;
	
	for(n=0;n<NO_OF_ITEMS;n++) 
	{
		Qty[n]=0; Tax[n]=0;
	}
	Price[BREAD] = 1;		Class[BREAD] = NON_GROC;
	Price[MILK]  = 2;		Class[MILK]  = NON_GROC;
	Price[SOAP]  = 3;		Class[SOAP]  = NON_GROC;
	Price[MUG]   = 5;		Class[MUG]   = GROC;
	Price[PLATE] = 5;		Class[PLATE] = GROC;
	
	for(n=0;n<NO_OF_ITEMS;n++) cout<<"\n\t\t"<<n+1<<"\t"<<Items[n]<<"\t\tPrice: US $ "<<Price[n];
	cout<<"\n\tEnter Age: "; cin>>Age;
	while(Flag)
	{
		cout<<"\n\tPress-1 for Bread";
		cout<<"\n\tPress-2 for Milk";
		cout<<"\n\tPress-3 for Soap";
		cout<<"\n\tPress-4 for Mug";
		cout<<"\n\tPress-5 for Plate";
		cout<<"\n\tPress-0 to Bill";
		while(Flag<0 || Flag>NO_OF_ITEMS)
		{
			cout<<"\n\tEnter Choice: "; cin>>Flag;
		}
		if(Flag>0 &&Flag<=NO_OF_ITEMS)	{cout<<"\n\tEnter "<<Items[Flag-1]<<" Quantity: "; cin>>Qty[Flag-1];}	
		if(Flag==0)
		{
			cout<<"\n\tBill";
			for(n=0;n<NO_OF_ITEMS;n++)
			{
				if(Qty[n]>0) 
				{
					Tax[n] = Price[n]*Qty[n]*0.08;
					cout<<"\n\tItem: "<<Items[n]<<"\tQty. : "<<Qty[n]<<"\tAmount: "<<Price[n]*Qty[n]<<"\tTax = "<<Tax[n]<<"\tTotal Amount: "<<Price[n]*Qty[n]+Tax[n];
					Total = Total + Price[n]*Qty[n] + Tax[n];
				}
			}	
			cout<<"\n\tTotal Amount: "<<Total;
			if(Age>=AGE_LIM) Discount = Total*0.05;
			cout<<"\n\tDiscount = "<<Discount;
			cout<<"\n\tNet Payable: "<<Total-Discount;
			getch(); exit(0);
		}	
		Flag=NO_OF_ITEMS+1;		
	}
}

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