a software company sells a package that retails for $99 . Quantity discounts are given according to this table.
Quantity Discount
10-19 20%
20-49 30%
50-99 40%
100 or more 50%
Write a program that asks for the number of units sold and computes the total cost of the purchase.
Input Validation: Make sure the number of units is greater than 0.
Here is what I wrote out, please tell me whats wrong with it.
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
#include <iostream>
#include <iomanip>
#include <string>
usingnamespace std;
int main()
{
double quantity, package = 99, cost; // declare variables as double since you are multiplying by .2
cout << "How many units sold? ";
cin >> quantity;
if ( quantity >= 10 && quantity <= 19)
{
cost = package * quantity - (0.2 * package * quantity); // your original equation was read like so. pa.ckage times quantity, now display 20% of that value. your goal is to discount 20%, not to charge them only 20%
cout << "Total cost is: " << cost << endl;
}
elseif ( quantity >= 20 && quantity <= 49)
{
cost = package * quantity - (0.3 * package * quantity);
cout << "Total cost is: " << cost << endl;
}
elseif ( quantity >= 50 && quantity <= 99)
{
cost = package * quantity - (0.4 * package * quantity);
cout << "Total cost is: " << cost << endl;
}
elseif ( quantity > 100 )
{
cost = package * quantity - (0.5 * package * quantity);
cout << "Total cost is: " << cost << endl;
}
elseif (quantity <10 && quantity >=1)
{
cost = package * quantity;
cout << "Total cost is: " << cost << endl;
}
system ("pause");
return 0;
}
Again, i havent worked with else or if or else if statements yet, (still learning the more simple stuff) but reading your code is what quite apparent there were math errors.
Thank you georgewashere (6) . It did not calculate the percentage, but I'll use your comments and changes to help make it work. I greatly appreciate your input.
georgewashere (6) It worked. I was entering 1 to test when I should have entered 10 or more. I have three more problems to do. I will use your code above to assist me.
When you don't know is a hell of a thing. The forum input goes a long way, you guys are the best, I will certainly help solve problems in the future.
Looking at the posted code, fixing it and reposting it gives us novice something to compare our ideas to, so that we can understand what we did wrong and grow from it. The comments in the code helped.