How do I create an algorithm for the following conditions?

I am writing a code for an online store. It's a school assignment. Here are the conditions and price:

Each DVD is $20.00

Every 6th DVD purchased is free. That is, for every 5 DVDs that you buy, you get an extra 1 free. For example, 5 or 6 DVDs would be the same price of $100.00 and 11 or 12 DVDs would be the same price of $200.00.

I have tried for several hours but cannot come up with a code that meets these requirements. I would really appreciate if someone helped me. Thanks in advance!
int Price = numDVDs*20 - int(numDVDs/6)*20; //Integer division always rounds down (the typecast isn't even technically necessary)
Last edited on
What code did you manage to come up with?
i havent come up with anything yet. Im trying to put an if statement in before the piece of code Niven suggested. So it should be if the the num of DVDs the customer buys give him one free dvd for every 5 he has. and if he enters 10, the 6th one in that should automatically be free. I dont know what to do :/
if (numDvds/6 >=1)
price = numDvds*20;
Last edited on
Topic archived. No new replies allowed.