As others have indicated, you need to convert your strings to integers before you can subtract.
Also, as a general rule, pay close attention to the error message:
Operator '-' cannot be applied to operands of type 'string' and 'string'
In this case, the problem is exactly what the compiler says: '-' can't be applied to strings.
Keep in mind that certain operations are only meaningful for certain types. Consider a few examples of edge cases if you try to do arithmetic on strings:
- "abc" - "c" (presumably, this means "string difference," in which
case the result should be "ab")
- "10" + "20": this is ambiguous because it could mean either "1020"
(string concatenation) or "30" (arithmetic addition). In reality, the compiler will always interpret this as concatenation and the result will be "1020".
- "abc" - "def" (if this is string difference, the result should be "abc")
- "abc" * "def": No clue what this means. Think about how the compiler would interpret this (it can't). This really should be a compile error, but it's not obvious how the compiler could "know" that it should be in the general case.
As you can see, when you try to do arithmetic operations on strings, there's no general way for the compiler to figure out what you intended to do. This is especially the case given that there are hard limits on the ability to reason about programs in an automated way (see, for example, the halting problem).
One more thing - look at the value of GroupLbl.Text
:
GroupLbl.Text = "Total discount: " + ((Kids * Price) * 0.75 + (Adults * Price) + (Seniors * Price) * 0.5) * 0.1;
This'll be something like "Total Discount: 10.0". What does "10.0" - "Total Discount: 10.0" mean? You're better off storing the total discount in a separate double or decimal variable.
double discount = ((Kids * Price) * 0.75 + (Adults * Price) + (Seniors * Price) * 0.5) * 0.1;
GroupLbl.Text = "Total discount: " + discount.ToString();
double totalAfterDiscount = double.Parse(TotalLbl.Text) - discount;
DiscountLbl.Text = "Total after discount: " + totalAfterDiscount.ToString();