|
-
April 16th, 2012, 04:17 AM
#1
Problems with my if else statement
Using net4.0 visual studio 2010
Hey guys I am designing a code as practice that asks the user to input the number of packages they bought and based on how many it will give them a discount and show them the total discounted price and also how much they got discounted.
For example if they bought between 10 and 19 packages they would get a 20% discount.
This is what I have written so far:
Code:
private void calculateButton_Click(object sender, EventArgs e)
{
const int SET_PRICE = 99;
int quantity;
double totalPrice;
double discountPrice;
double discountAmount;
quantity = int.Parse(quantityTextBox.Text);
if (quantity <= 19 || quantity > 10)
{
totalPrice = quantity * SET_PRICE;
discountPrice = totalPrice * 0.80;
discountAmount = totalPrice * 0.20;
discountLabel.Text = discountPrice.ToString("c");
discountAmountLabel.Text = discountAmount.ToString("c");
}
else if (quantity <= 49 || quantity >= 20)
{
totalPrice = quantity * SET_PRICE;
discountPrice = totalPrice * 0.70;
discountAmount = totalPrice * 0.30;
discountLabel.Text = discountPrice.ToString("c");
discountAmountLabel.Text = discountAmount.ToString("c");
Every time I type a quantity over 19 (say i type 20) it gives me the completely wrong discount every single time. From what I can see it is completely ignoring my second if else statement and still calculating it with the percentages from my first if statement. Can anyone point me in the wrong direction here? Why is it skipping my if else statement and still using my if statement even if I specified over 19 packages.
Last edited by DataMiser; April 16th, 2012 at 05:08 PM.
Reason: added code tags
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|