I have to make a program that asks to enter the # of boxes bought. Then it should display the amount of the discount and the total cost of the purchase after the discount. Each box retails for $50. The problem I'm having is connecting the if else then function to the cost.

cout<<" Units sold: ";
cin>> cost;

cout<<"Total cost " << cost;


cost=(cost * 50);
discount = (50 - cost);

if (cost < 5)
cost=(cost * 50);

else if (cost > 5 && cost < 10);
cost=(50 - (50 * 0.2));

else if (cost > 10 && cost < 20)
cost=(50 - (50 * 0.3));

else if (cost > 20 && cost < 30)
cost=(50 - (50 * 0.4));

else if (cost > 30);
cost=(50 -(50 * 0.5));

3 things:

1. What output are you expecting and what output do you get? We're not really mindreaders here, so you might want to clarify this.

2. When posting code ALWAYS use code-tags

3. You have a small bug in your code:

else if (cost > 10 && cost < 20)
[...]
else if (cost > 20 && cost < 30)

What you're saying is:
if cost if bigger then 10 and smaller then 20
if cost is bigger then 20 and smaller then 30
etc
But what happens if cost is exactly 20?? Hint: >=

1) The output should display the amount of the discount and the total cost of the purchase after the discount. So the cost after the discount.

3) I know about the exact values but my main concern is for the program to actually work.

All it does now is asking "Units sold." When you type the units, it displays what your cost is. Whatever you put for the units sold, the price always comes back as $0.

So basically
Units Sold = 50
Price = $0

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.