This has nothing to do with DateTime so I don't know why this keeps popping up, here is the code I'm using. When you press calculate after entering the required text its supposed to display the price then calculate the discount and finally display the final price.
The line that comes with the error - decimal price = Convert.ToDecimal(txtPrice.Text);
txtPrice is empty, or more specifically read only, the variable 'price' should set it to 100 or whatever I want from my if statement, correct?
Btw the price isn't supposed to be 100 for each section, kept changing the code slightly to make the error go away so I just copied and pasted "price = 100;" so I didn't have to type a different number each time.
private void btnCalculate_Click(object sender, EventArgs e)
{
int tenure = Convert.ToInt16(txtTenure.Text);
string seatingType = txtLocation.Text;
decimal discountPercent = .0m;
decimal price = Convert.ToDecimal(txtPrice.Text);
if (seatingType == "Main")
{
price = 100;
if (tenure >= 6)
discountPercent = .5m;
else if (tenure >= 12)
discountPercent = .75m;
else if (tenure >= 24)
discountPercent = 1.0m;
}
else if (seatingType == "Pit")
{
price = 100;
if (tenure >= 12)
discountPercent = .5m;
else if (tenure >= 12)
discountPercent = .75m;
else if (tenure >= 24)
discountPercent = 1.0m;
}
else if (seatingType == "Balcony")
{
price = 100;
if (tenure >= 12)
discountPercent = .5m;
else if (tenure >= 12)
discountPercent = .75m;
else if (tenure >= 24)
discountPercent = 1.0m;
}
decimal discountAmount = price * discountPercent;
decimal finalPrice = price - discountAmount;
txtFinalPrice.Text = finalPrice.ToString("c");
}
I'm using a textbook example and everything looks correct, not sure why this is happening.