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

IOS Development : Functions challenge test 1

This is my solution : float addTwo(float a, float b); float addTwo(float a, float b) { float a = 13.14; float b = 23.23; float result = a + b; printf("%f", result); return result; }

4 Answers

Stone Preston
Stone Preston
42,016 Points

This is my solution : float addTwo(float a, float b) { float a = 12.21; float b = 12.212; float result = a + b; retun result; }

remember you dont need to declare any local variables in the body of the function. Use the parameters a and b you defined in the function header. you also misspelled return

float addTwo(float a, float b) {
 float result = a + b;
 return result; 
}
Stone Preston
Stone Preston
42,016 Points

all you need to do is implement the function. you do not need to declare any variables, you dont need a function prototype. all you need is the function implementation. 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.

Hi Stone,

Thank you for you reply.

This is my solution : float addTwo(float a, float b) { float a = 12.21; float b = 12.212; float result = a + b; retun result; }

But still the return error is: Make sure you've defined the return type and both paramter types as 'float' and that you are returning the sum of the arguments as a result.

Oh my fault. Thank you for your help Stone.