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

Cant figure out this iOS question

Ive tried this code but can't figure out where to put the "float" identifier

void addTwo(a,b){ int here = a+b; return here; }

https://teamtreehouse.com/library/functions

1 Answer

In this challenge and generally with Objective-C you have to declare every variable type. So for this particular question they were looking for:

float addTwo(float a, float b){  return a+b; }

The first float is the type of variable that you are returning. By putting void in your code, you're actually telling the compiler that this function is not going to return a value, so that's the first thing. Second, you need to declare the types of variables that the function will be passed. That's the float in front of the a and b variables. Then because the function already knows that a and b are of type float, you can just return the two added together. Hopefully this helps.