Here is my code for a store that will display products let the user pick which i
ID: 3528465 • Letter: H
Question
Here is my code for a store that will display products let the user pick which items and the quantity they want then once they exit it will display a customer reciept. My problem is the customer can recieve 3 different discounts, 10% 15% and 20%, to decide which of these the customer should get I have an if statement that declares the discount_perecent, but when I run this code it says that discount_percent is not declared in the float discount = (pretax_total*discount_percent) line. I'm not sure what I'm doing wrong here any help would be appreciated. Thanks!
#include <iostream>
using namespace std;
int main()
{
//2 digits after decimal
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
//Initial variable declaration
int choice;
float widget = 24.99;
float gizmo = 49.99;
float generic_assembly = 74.97;
int widget_quantity = 0;
int gizmo_quantity = 0;
int generic_assembly_quantity = 0;
const float taxrate = 0.0885;
//variable equations for reciept
float pretax_total = (widget*widget_quantity)+(gizmo*gizmo_quantity)+(generic_assembly*generic_assembly_quantity);
if(pretax_total >= 100.00 && pretax_total <= 199.99)
float discount_pecent = .10;
else if (pretax_total >= 200.00 && pretax_total <= 399.99)
float discount_pecent = .15;
else if (pretax_total >= 400.00)
float discount_pecent = .20;
else if (pretax_total < 100.00)
float discount_pecent = 0;
float discount = (pretax_total*discount_pecent);
float sub_total = (pretax_total-discount);
float tax = (sub_total*taxrate);
float final_total = (sub_total+tax);
//Menu Launch
cout<<"Welcome to Widgets & Such! ";
cout<<"We have great discount news: ";
cout<<"Spend $100, 10% off ";
cout<<"Spend $200, 15% off ";
cout<<"Spend $400, 20% off ";
cout<<"The types of items in stock are listed: ";
cout<<"Widget $24.99 ";
cout<<"Gizmo $49.99 ";
cout<<"Generic Assembly $74.97 ";
//Menu loop
bool menu=true;
while (menu != false) {
cout<<"Please enter your choice: ";
cout<<"1-Buy Widgets ";
cout<<"2-Buy Gizmos ";
cout<<"3-Buy Generic Assemblies ";
cout<<"4-Checkout ";
cin>>choice;
switch(choice)
{
case 1:
cout<<"Enter Quantity: ";
cin>>widget_quantity;cout<<" ";
cout<<"Your items have been purchased. ";
cout<<endl;
break;
case 2:
cout<<"Enter Quantity: ";
cin>>gizmo_quantity;cout<<" ";
cout<<"Your items have been purchased. ";
cout<<endl;
break;
case 3:
cout<<"Enter Quantity: ";
cin>>generic_assembly_quantity;cout<<" ";
cout<<"Your items have been purchased. ";
cout<<endl;
break;
case 4:
cout<<"Thank you for shopping with us. ";
menu=false;
break;
default:
cout<<"Not a valid choice. ";
cout<<"Choose again. ";
cout<<endl;
break;
}
}
//Customer Reciept
cout<<"Customer Copy of Reciept ";
cout<<"--------------------------------------- ";
cout<<"Item Quantity Price ";
cout<<"Widget "; cout<<widget_quantity;cout<<" "; cout<<(widget*widget_quantity);cout<<" ";
cout<<"Gizmo "; cout<<gizmo_quantity; cout<<" "; cout<<(gizmo*gizmo_quantity);cout<<" ";
cout<<"Generic Assembly "; cout<<generic_assembly_quantity; cout<<" "; cout<<(generic_assembly*generic_assembly_quantity);cout<<" ";
cout<<"--------------------------------------- ";
cout<<"Total (Before Discount) ";cout<<pretax_total;cout<<" ";
cout<<"Discount ";cout<<"-";cout<<discount;cout<<" ";
cout<<"--------------------------------------- ";
cout<<"Total Pretax ";cout<<sub_total;cout<<" ";
cout<<"Sales Tax ";cout<<tax;cout<<" ";
cout<<"--------------------------------------- ";
cout<<"Your Final Total ";cout<<final_total;
return 0;
}
Explanation / Answer
let me try debugging code. will post link to code once done debugging
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.