please help! I have not idea how to fix this.I am stuck on this and it has been a while. What should this code look like at lease the error is in line 8-10
int intAmountA = 0;
int intAmountB = 0;
int intAmountC = 0;
decimal decPackageA = 0m;
decimal decPackageB = 0m;
decimal decPackageC = 0m;
decimal decTotal = 0m;
intAmountA = TxtAmountA.Text;
intAmountB = TxtAmountB.Text;
intAmountC = TxtAmountC.Text;
decPackageA = intAmountA * 150;
decPackageB = intAmountB * 120;
decPackageC = intAmountC * 90;
LblPackageA.Text = decPackageA.ToString("c");
LblPackageB.Text = decPackageB.ToString("c");
LblPackageC.Text = decPackageC.ToString("c");
decTotal = decPackageA + decPackageB + decPackageC;
LblTotal.Text = decTotal.ToString("c");
The TxtAmountA.Text is a string. You are attempting to set the variable intAmountA which is an integer to a string value, thus the error. You need to parse the integer out of the string in the textbox.
intAmountA = int.Parse(TxtAmountA.Text);
However, be aware that if what is in TxtAmountA.Text is not something that can be cast to an integer, you will get an exception. That is when you can use the conditional int.TryParse(string value, out integer);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With