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

Hey Guys, i need help. i wrote a code on Xcode and it ran just fine, but the challenge says its wrong. any ideas?

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.)

and this is the code i wrote:

include <stdio.h>

float addTwo(float a, float b); int main() {

float a = 3.5;
float b = 2.5;
printf("%f", addTwo(a, b));
return 0;

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

}

1 Answer

This challenge just wants the Function implementation, so you don't have to include main. Also, you don't need the printf statement. Follow this format:

returnType functionName(dataType argument1, dataType argument2){

return something
}

You almost have it exactly right, just slim it down to the necessities and correct your return statement. No need to define float a or b.

Thank you, I got it.. :D

Awesome! Good luck with the rest of the course :)

Stone Preston
Stone Preston
42,016 Points

You need to include the data type of the parameters as well.

Ah yes, thanks for the reminder.