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 Object-Oriented Objective-C Tying it All Together Cumulative Review

Luis Paulino
PLUS
Luis Paulino
Courses Plus Student 1,779 Points

help, I'm not sure what's wrong with the grammar of the code.

I think the problem is rather simple, but i can't understand the preview. I would like to suggest that Treehouse give classes on how to read the preview, so I don't have to wait for help. Not that I don't love you guys for helping.

variable_assignment.mm
NsArrray *temps= [@"75.5"@"83.3"@"96"@"99.7"];
  float *average;

1 Answer

Hi Luis,

You're close there.

First, correct the typing to NSArray. Next, separate the numbers with a comma and precede the square brackets with the @ symbol. Also, this is an array of numbers, not strings, so remove all the "" marks.

Your float is correct. This all looks like:

NSArray *temps= @[@75.5, @83.3, @96, @99.7];
float average;

I hope that helps,

Steve.

Luis Paulino
Luis Paulino
Courses Plus Student 1,779 Points

hey since, your a tree house mod can you suggest to the treehouse team that they should teach us students how to properly read the outcome of the preview button. please, I think it would be a big help.

Hi Luis,

I'm not sure that's possible, if I'm honest. To teach you to read the errors is the same as understanding why the code is wrong, i.e. you need to understand the correct code.

Your initial post gives the following error:

expected identifier
    NsArrray *temps= [@"75.5"@"83.3"@"96"@"99.7"];

That's a very generic error - there's enough wrong with the code that the compiler can't pinpoint the precise issue; it is just saying something's wrong. We knew that already!

Correcting the datatype to NSArray gives us the same. There's too much for the compiler to be specific.

Adding commas between the array element gives the same issue too - the compiler doesn't know what you're trying to do to guide a specific error message.

Adding the preceding 'at' symbol produces a very bizarre error:

objective_c.mm:43:34: error: invalid operands to binary expression ('float *' and 'double')
      if(average == 0 || average == 88.625){

The code looks like this right now:

NSArray *temps= @[@"75.5", @"83.3", @"96", @"99.7"];
  float *average;

This is whining about the float pointer and the double contained in the test. Removing the pointer asterisk clears the error as the code compiles syntactically. And it passes the challenge task too; should it?? I'm not sure it should; but it does.

The remaining test passes too, even though the array is populated with strings, not NSNumbers. Hey ho - the compiler isn't as picky as it could be.

My point is that teaching you what ...

objective_c.mm:43:34: error: invalid operands to binary expression ('float *' and 'double')
      if(average == 0 || average == 88.625){

... this means is more work than teaching you to spell NSArray correctly. Attention to detail is more important. If you know the code is wrong; find the error. The Preview may assist with that but you know there's something wrong inside your code. You had written two lines of it - there's not much to check, surely?

Keep asking questions; tag me if you want direct help - use a Twitter-style 'at' symbol (like this -> Luis Paulino )or 'ask' me in the list below, if I appear.