1. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Nov 2010
Posts
10
Rep Power
0

#### Easy Logic Question

Hey guys we were assigned to do Logic homework via codingbat.

I am really stuck on this particular part.

Directions:
When squirrels get together for a party, they like to have cigars. A squirrel party is successful when the number of cigars is between 40 and 60, inclusive. Unless it is the weekend, in which case there is no upper bound on the number of cigars. Return true if the party with the given values is successful, or false otherwise.

cigarParty(30, false) → false
cigarParty(50, false) → true
cigarParty(70, true) → true
My following attempt at this code:
PHP Code:
```   public boolean cigarParty(int cigars, boolean isWeekend) {    if( (cigars >= 40 && cigars <=60) && !isWeekend)   {   return true;      }      else if( cigars > 1 && cigars < 100 && isWeekend)   {   return true;   }      else {   return false;   }      }  ```
My outcome:
PHP Code:
```    Expected    This Run         cigarParty(30, false) &#8594; false    false    OK         cigarParty(50, false) &#8594; true    true    OK         cigarParty(70, true) &#8594; true    true    OK         cigarParty(30, true) &#8594; false    true    X         cigarParty(50, true) &#8594; true    true    OK         cigarParty(60, false) &#8594; true    true    OK         cigarParty(61, false) &#8594; false    false    OK         cigarParty(40, false) &#8594; true    true    OK         cigarParty(39, false) &#8594; false    false    OK         cigarParty(40, true) &#8594; true    true    OK         cigarParty(39, true) &#8594; false    true    X         other tests         OK  ```
I dont understand what I am doing wrong. Can anyone explain?
2. Obviously, your logic is wrong.

If it is the weekend, as long as the count is the minimum, the max count of cigars doesn't matter.

Else, (it's not the weekend, and) the count of cigars should be within the range.
3. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Nov 2010
Posts
10
Rep Power
0
Originally Posted by TheOtherDino

If it is the weekend, the count of cigars doesn't matter.

Else, the count of cigars should be within the range.
Thats the thing I am not sure how to write that in code.
ive been struggle the past hour with no prevail

How do we create the count doesnt matter?
4. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Nov 2010
Posts
10
Rep Power
0
Originally Posted by DelaySix
Thats the thing I am not sure how to write that in code.
ive been struggle the past hour with no prevail

How do we create the count doesnt matter?
Okay never mind I got the program to work I was missing a part of it haha