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

David Dassau
David Dassau
8,628 Points

I am having trouble with this question

Implement a function named "addTwo" that returns the sum of two floats. The function will accept two float numbers as arguments. It should add the two arguments together, and return the result. (No need to write the main function. Just write out the implementation for the addTwo function.)

2 Answers

Stone Preston
Stone Preston
42,016 Points

all you need to do is implement the function. here is a shell of what your function should look like:

returnType functionName(dataType parameterOne, dataType parameterTwo) {

return something;

}

the challenge tells you it needs to be named add two, it needs to take two arguments (these are your parameters). these arguments need to be of the type float. then you need to return the sum of the parameters. since you are returning the sum of 2 floats your return type needs to be a float.

note that I called the variables inside the parenthesis parameters. When implementing a function, the variables you put inside the ( ) are known as parameters. When calling a function, they are arguments.

David Dassau
David Dassau
8,628 Points

Thank you! I saw your reply to this same question for another person in the forum. I tried it again, and was still getting it incorrect. It turns out I was just adding a semi-colon where I didn't need one.

Stone Preston
Stone Preston
42,016 Points

awesome glad you figured it out. those semicolons can be tricky