Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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