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

how do i confirm my divisions???

Please help

variable_assignment.mm
NSArray *temps= @[@75.5, @83.3, @96, @99.7];
float average;
float runningTotal;
for(float average in tempsArray){ 
     floatrunning total=[value of Avarge];

1 Answer

Hi Luis,

You have an array called temps which you want to iterate over using a for loop.

You've created a new variable of type float for the iteration. That's not what you want. Your array is full of NSNumber objects, so use a new NSNumber. As this is a new variable you'll need the pointer marker too. I called my variable x because that's easy and local to the loop only.

Inside the loop you want to add up the contents of your array, which is called temps not tempsArray. Store that cumulative value in runningTotal. As runningTotal is a float you need to cast the value of x before you can add it to the variable. The question explains how to do that. with my variable called x it look like [x floatValue].

After the loop has ended, divide runningTotal by the length of the array (use the [count] attribute). Store the result of that in the variable average you created in task 1.

Let me know how you get on - post your code and we'll work through it.

Steve.