Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Objective-C Basics Introduction to Operators and Conditionals Review IF / ELSE

guys really stuck on this task 2 of 2.

bool hasBonus; int powerPoint = 5; if ( hasBonus <= powerPoint) { hasBonus = false; } else ( hasBonus >= powerPoint) { hasBonus = true; }

variable_assignment.mm
bool hasBonus;
int powerPoints = 5;
if (hasBonus <= powerPoints) {
  hasBonus = false; }
else (hasBonus >= PowerPoints) {
  hasBonus = true; }

2 Answers

Martin Wildfeuer
PLUS
Martin Wildfeuer
Courses Plus Student 11,071 Points

Hey there! Unfortunately, the link to the assignment is missing, so I'll try to give you a more general answer:

With this code, you are trying to compare a boolean with an int. I added comments with pseudo code, so you can see what I mean:

bool hasBonus;
int powerPoints = 5;

 // if (bool hasBonus <= int powerPoints) { 
if (hasBonus <= powerPoints) {
  hasBonus = false; }
 // if (bool hasBonus >= int powerPoints) { 
else (hasBonus >= PowerPoints) {
  hasBonus = true; }

What you are most likely up to is comparing the powerPoints to another int, so you can assign true or false to hasBonus when the player has the needed power points to get the bonus. This could look like this:

bool hasBonus;
int powerPoints = 5;

// If player has 10 power points or more...
if(powerPoints >= 10) {
   // ...player will get the bonus
   hasBonus = true
// ... in every other case, that is any int that is lower than 10...
} else {
   // ...player won't get the bonus
   hasBonus = false
}

Again, see how that applies to your challenge.

Hope that helps :)

A'Bool' data type only contains 'True' and 'False' values. But because you did not assign a value to 'hasBonus' it does not contain any value. So essentially you are comparing a 'null' value to an integer value which is why it won't work. If your goal is to set the 'Bool' value then you need to compare the int value to another int value. Also, an 'else' statement does not use a comparison statement; it simply evaluates if the 'if' statement is false.

    bool hasBonus;
    int powerPoints = 5;

    if (powerPoints <= 5) {
        hasBonus = false;
    } else {
        hasBonus = true;
    }