March 10th, 2013, 10:39 PM
Hello there! I am fairly new to C# and I'm having a problem coding a specific assignment. I was wondering if anyone could provide a few tips on what I'm doing wrong. I'm trying to have it catch 3 different things. That there is a decimal value, that there actually is something inserted, and that the number is within range of 0 and 1000. All of these need to display a different message box also. Down below is so far what I've done. I'm able to do the valid range but it's still calculating the numbers when I click calculate. Aslo when there is no value entered it brings up the "Please enter a valid subtotal" message box instead of the "Requires Subtotal" box. Thanks!
private void btnCalculate_Click(object sender, EventArgs e)
decimal subtotal = Decimal.Parse(txtSubtotal.Text);
if (subtotal < 0 || subtotal > 1000)
MessageBox.Show("Please enter a valid range");
if (txtSubtotal.Text == "")
decimal discountPercent = .25m;
decimal discountAmount = subtotal * discountPercent;
decimal invoiceTotal = subtotal - discountAmount;
discountAmount = Math.Round(discountAmount, 2);
invoiceTotal = Math.Round(invoiceTotal, 2);
txtDiscountPercent.Text = discountPercent.ToString("p1");
txtDiscountAmount.Text = discountAmount.ToString();
txtTotal.Text = invoiceTotal.ToString();
MessageBox.Show("Please enter a valid subtotal");
Last edited by DataMiser; March 13th, 2013 at 01:43 AM.
Reason: added code tags for readability
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.