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

Carefully, read the code below. Which customerAge ranges won’t be handled correctly? int customerAge; floa

Carefully, read the code below. Which customerAge ranges won’t be handled correctly?

int     customerAge;
float   ticketPrice;

customerAge = 13;

if(customerAge < 13){
    ticketPrice = 5.00;
}

if (customerAge >= 65){
    ticketPrice = 6.00;
}

else{
    ticketPrice = 10.00;
}

1 Answer

It needs something to break the else statement. So say the customer age is 10. They are less than 13 so the price would be set to 5.00. They are not greater or equal to 65 so nothing happens there. As the statement didn't break at the first statement it carries on to the final part and sets the price to 10.00. This just highlights that you need a break in your if statement or someway of getting out of them.

Cheers