View Single Post
Old 10-12-2004, 12:02 AM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,720
redhead is on a distinguished road
Quote:
Code:
else if (quantity <= 9)
  totalCostOfPurchase = price * quantity;
else if (quantity >= 10)
  totalCostOfPurchase = price * quantity - discount1;
else if (quantity <= 19)
A value of 0 is below 9, thus the calculation starts.
This can be handlet in the if(quantity <= 0) put a return state here, and it will never go any further.

Also with the furhter calculations theres is a misshap, if a value of 15 or 20 for that matter is entered, only the
totalCostOfPurchase = price * quantity - discount1;
is beeing calculated, it never goes any further..

You need to make a more precise if() clause ie:
Code:
else if (quantity >= 0 && quantity <= 9)
  totalCostOfPurchase = price * quantity;
else if (quantity >= 10 && quantity <= 19)
  totalCostOfPurchase = price * quantity - discount1;
else if (quantity >= 20 && <= 49)
  totalCostOfPurchase = price * quantity - discount2;
etc....
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote