Donald Waltman
Donald Waltman

Reputation: 1

Boolean function

I am trying to use a find_if Boolean function to return true if:

  1. Z is =<10;
  2. name="john" (all lower case)

My code:

/* predicate for find_if */
bool exam_pred(const exam_struct &a)
{
  if ((a.Z=<10)&&(a.name="john")) 
  {
     return true;
  }   
}

exam_struct{
  int x,y;
  double Z;
  string name;
};

It doesn't compile when I set a.name="john". So my question is how do implement the a.name="john"; into my boolean?

Upvotes: 0

Views: 249

Answers (2)

Elazar
Elazar

Reputation: 21635

you should indeed use the == operator.

I was wrong suggesting strcmp before, since you are using strings.

code:

struct exam_struct {
    int x, y;
    double Z;
    string name;
};

/* predicate for find_if */
bool exam_pred(const exam_struct& a)
{
    return a.Z <= 10 && a.name=="john";
}

note that in your original code you do not return false when the check false.

Upvotes: 3

Niels Keurentjes
Niels Keurentjes

Reputation: 41968

= is the assignment operator. Use == for equality comparisons. And the smaller-or-equals operator is <=, not =<.

Upvotes: 2

Related Questions