I need abit of help with an if statement and operators. How could I do this:
double AgePenalty = 0;
if (AgeOfCustomer <= 21)
{
AgePenalty = 15;
}
if (AgeOfCustomer <= 30 && AgeOfCustomer => 21) // cant use && operator with double
{
AgePenalty = 10;
}
This just says if the customer is younger than 21 apply a certain price tag; if the customer is between the ages of 21 and 25 apply smaller price tag etc.
Your check AgeOfCustomer => 21 is wrong, it should be : AgeOfCustomer >= 21
Just change your if statement to
if (AgeOfCustomer <= 30 && AgeOfCustomer >= 21)
It's not && that's the problem - it's your greater-than-or-equal-to operator, which is >=, not =>.
if (AgeOfCustomer <= 30 && AgeOfCustomer >= 21)
=> is used for lambda expressions.
(It's not clear why you thought this was related to doubles particularly...)
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