# C++ math question

• 09-12-2005
newbiec++
C++ math question
I have a math problem. I have 3 categories of customers:
old
new
temporary

They can purchase books at the following rates:

old: 1-5 purchased = 50.00 each
6 or more = 45.00 each

new: 1-5 purchased = 35.00 each
6 or more = 30.00 each

temporary: 1-5 purchased = 20.00 each
6 or more = 15.00 each

Thanks :p
• 09-12-2005
Enahs
So whats the math problem?
• 09-12-2005
newbiec++
Do I use if / else or is there a simpler way to do it with an equation?
• 09-12-2005
Enahs
Sure, if-else will work here.

Making some assumptions on what you are doing and how, it might look something like this:

Code:

```if (number_of_books_purchased < 6) {         old_total = (number_of_books_purchased * 50);         new_total = (number_of_books_purchased * 35);         temp_total = (number_of_books_purchased * 20); } else {         old_total = (number_of_books_purchased * 45);         new_total = (number_of_books_purchased * 30);         temp_total = (number_of_books_purchased * 15); }```

This puts them in a variable_total all on its own (which you would have to declare). Do not know if that is what you wanted/how you wanted to code, but this is far from the only way.

But uhh, why are you ripping off all your old and faithfull customers by making them pay so much more!
• 09-12-2005
newbiec++
That is exactly what I was looking for. I thought if/else would be o.k. but was not sure.
Not really ripping off old faithful this was just some random numbers.
Thanks
• 09-12-2005
major_small
you'll find that usually a good way to start out is to write out exactly what it is you need to do in english. when you've done that, you'll usually find it's easy to translate that into code.

the english version is called psuedocode, and what you're doing is devising an algorithm.
• 09-13-2005
Enahs
Quote:

the english version is called psuedocode, and what you're doing is devising an algorithm.
What is it called when it is in French?

wait for it.....wait for it...