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 (Retired) Functional Programming in C Functions

Rami Ammoun
Rami Ammoun
7,468 Points

Stuck in the Objective of this stage

Hi, I know the solution might be quite simple, but i've been trying for almost an hour. I tried to look into the forms for a solution, nothing worked, and I gave up.

My code for the addTwo function were as follows:

int addTwo(float first, float second){ float first = 1.0; float second = 2.0; float sum = first + second; return sum; }

any solutions please?

3 Answers

Rami Ammoun
Rami Ammoun
7,468 Points

This code worked:

float addTwo(float first, float second){
    float sum = first + second;
    return sum;
}
Mikael Enarsson
Mikael Enarsson
7,056 Points

Ops, sorry for not getting back to you, I totally missed your answer. Good job solving it though!!

ruo pu koh
ruo pu koh
2,669 Points

Where did the function float come from!?

Reading this codes makes sense. But it looks nothing like any of the tutorials from the video.

so confused...

Mikael Enarsson
Mikael Enarsson
7,056 Points

Nick is almost right, but you also have to change the return type to float.

Rami Ammoun
Rami Ammoun
7,468 Points

Hi Mikael, I tried the code Nick suggested and I received an error:

"Bummer! The function does not appear to be returning the correct value. Is the return type a float?"

Can you tell me how to change the return type to float? I appreciate ur help

As you can see, you already defined float first and second as parameters. Remove this:

 float first = 1.0;
 float second = 2.0; 

If you did that, you should have this:

int addTwo(float first, float second){
    float sum = first + second;
    return sum;
}

This should give you the desired result! Let me know if you have anymore questions.

Rami Ammoun
Rami Ammoun
7,468 Points

Thank you Nick,

I still get the following error:

"Bummer! The function does not appear to be returning the correct value. Is the return type a float?"

Rami Ammoun
Rami Ammoun
7,468 Points

I found the solution, I just had to change the 'int' in the declaration to float

the code was as follows:

float addTwo(float first, float second){
    float sum = first + second;
    return sum;
}

Thanks for your help!