Answer to Question #12290 in C++ for Mindy Smith

Question #12290
I need to write an efficient working program using C++ that is free of syntax and logical errors. It must include appropriate comments and directives, at least one const variable, 1 selection and 1 repetition structure, and an output that includes a subtotal and grand total. Can I get an example of this?
1
Expert's answer
2012-07-26T09:48:52-0400
#include <iostream>
using namespace std;
int main()
{
//
initializing the variables:
const unsigned int iterations = 3;
const float
bonusRate [] = {0.05f, 0.10f};
int productID;
float salesAmount;
float
subtotal = 0.0f;
float bonus = 0.0f;

for (unsigned int i = 0; i <
iterations; i++)
{
// getting the data from user:
cout << "Please
enter the product ID (1, 2, 3): " << endl;
cin >>
productID;
cout << "Please enter the amount of sales: " <<
endl;
cin >> salesAmount;
subtotal += salesAmount;
// adding the
bonus according to product ID:
switch (productID)
{
case 1:
// fixed
bonus for product #1
bonus += 1.0f;
break;
case 2:
// bonus rate 5%
for product #2
bonus += salesAmount * bonusRate[0];
break;
case
3:
// bonus rate 10% for product #3
bonus += salesAmount *
bonusRate[1];
break;
default:
break;
}
}
// output:
cout
<< "Subtotal: " << subtotal << endl;
cout << "Total:
" << (subtotal + bonus) << endl;
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