Question
C++ Also, instead of having case statements for both upper and lower case letters, use the tolower method to make the users customer_type entry to
C++
Also, instead of having case statements for both upper and lower case letters, use the tolower method to make the users customer_type entry to lowercase, then only check for the lowercase letter in the case statement. Remove any unused/commented out code.
#include
using namespace std;
int main() { // display title cout << "The Invoice Total Calculator 2.0 ";
// get input char customer_type; cout << "Enter customer type (r/w/n/c): "; cin >> customer_type;
double subtotal; cout << "Enter subtotal: "; cin >> subtotal;
// set discount percent double discount_percent; switch (customer_type) { // RETAIL case 'r': case 'R': if (subtotal < 100) { discount_percent = .0; } else if (subtotal >= 100 and subtotal < 250) { discount_percent = .1; } else if (subtotal >= 250 and subtotal < 500) { discount_percent = .2; } else { discount_percent = .3; } break; // WHOLESALE case 'w': case 'W': if (subtotal < 500) { discount_percent = .4; } else { discount_percent = .5; } break; // non-profit case 'n': case 'N': discount_percent = .3; break; // COLLEGE case 'c': case 'C': discount_percent = .25; break; // OTHER default: discount_percent = .0; break; }
// calculate and round results double discount_amount = subtotal * discount_percent; discount_amount = round(discount_amount * 100) / 100;
double invoice_total = subtotal - discount_amount; invoice_total = round(invoice_total * 100) / 100;
// display output cout << "Discount percent: " << discount_percent << endl << "Discount amount: " << discount_amount << endl << "Invoice total: " << invoice_total << endl << endl;
cout << "Bye! "; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started