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

ARRON HIRST
ARRON HIRST
573 Points

Can someone explain why the answer is $10?

Quiz question 2 of 3 on the Basics of Objective-C course asks which age ranges will not be handled correctly, based on the code for a mythical theatre ticketing system.

The correct answer is shown as being β€œAll ages under 13.”

The question presents the following code:

int customerAge; float ticketPrice;

customerAge = 13;

if(customerAge < 13){
    ticketPrice = 5.00
}

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

else{
    ticketPrice = 10.00
}

While I understand that the customer is 13, and will therefore be charged $10, I don't yet understand why everyone under the age of 13 is not handled correctly, as that age group would surely be charged $5? And 13 to 64 year olds would be charged $10?

Therefore, wouldn't the correct answer be that 13 to 64 aren't handled correctly?

Can someone please explain for me?

Thanks, Arron

2 Answers

ARRON HIRST
ARRON HIRST
573 Points

Oops. I just realised that a similar question has been asked by someone else in the β€œReview IF ELSE” forum , and the thread in question thankfully has a clear and concise explanation to my question - too.

Thread: https://teamtreehouse.com/community/i-have-a-doubt-in-the-quiz-carefully-read-the-code-below-which-customerage-ranges-won-t-be-handled-correctly

Mauricio Zambrano
Mauricio Zambrano
14,849 Points

You miss an else statement you are doing 2 separated comparisons 2 different if