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

i have no idea how to write this code at all

Write a function named "addTwo" that accepts two float numbers as arguments. The function should also return a float which is the sum of the two arguments passed to the function.

Amit Bijlani or Douglass Turner can you please show me the answer because i don't know how By the way I'm 11 years old

6 Answers

Stone Preston
Stone Preston
42,016 Points

writing a function usually looks something like this

returnType functionName(dataType arguementOne, dataType argumentTwo) {

    //do whatever you need to do
    return something;
}

the question gives you the return type, the function name, the datatype and number of arguments and tells you what you need to do inside the body of the function (return a float thats the sum of two arguments).

Thomas Nilsen
Thomas Nilsen
14,957 Points

Try watching the video one more time.

It should be something like this:

<return type> <name of function> (<datatype> argument1, <datatype> argument2){
   return (argument1 + argument2);
}

I'm having trouble with this challenge as well. I typed: float addTwo(float a, float b) { return (a + b); } //and it isn't working.

That is correct move on from the section until it's fixed

Thats correct but there shouldnt be no parentheses in the return... so { return a + b; } also theres something wrong with the challenege ATM

ok thanks

Amit Bijlani
STAFF
Amit Bijlani
Treehouse Guest Teacher

Some recent changes to challenge broke it. Sorry about the inconvenience but it should work now.