Understanding bool functions in product comparison?

  • Thread starter Thread starter torquerotates
  • Start date Start date
  • Tags Tags
    Confused Functions
AI Thread Summary
The discussion centers on a member function in C++ that compares two products based on their price and score. The key confusion arises from the line "return score/price>b.score/b.price," which determines if one product is better than another. It is clarified that this line returns true if the condition is satisfied and false otherwise. The conversation emphasizes understanding boolean comparisons as functions that yield true or false based on specified conditions. Overall, the explanation helps clarify how boolean functions operate within the context of product comparison.
torquerotates
Messages
207
Reaction score
0

Homework Statement



I'm given the member function:

bool Product::is_better_than(Product b) const
{
if(price==0) return true;
if (b.price price==0) return false;
return score/price>b.score/b.price;
}

I'm really confused about the last line "return score/price>b.score/b.price;". Does it mean, return true if ">" holds and return false if "<" doesn't hold?
 
Physics news on Phys.org
Yes. You can think of all comparisons as functions that return true or false depending on whether the condition is satisfied.
 
oh I see. Thanks
 

Similar threads

Replies
3
Views
2K
Replies
2
Views
4K
Replies
14
Views
5K
Replies
1
Views
2K
Replies
7
Views
4K
Replies
2
Views
1K
Back
Top