Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

&& operator for double

Tags:

c#

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.

like image 725
G Gr Avatar asked Nov 28 '25 06:11

G Gr


2 Answers

Your check AgeOfCustomer => 21 is wrong, it should be : AgeOfCustomer >= 21 Just change your if statement to

  if (AgeOfCustomer <= 30 && AgeOfCustomer >= 21)
like image 80
Habib Avatar answered Nov 30 '25 21:11

Habib


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...)

like image 45
Jon Skeet Avatar answered Nov 30 '25 20:11

Jon Skeet