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

What are you looking for

int addTwo(float a, float b); int main() { float first = 24; float second = 35;

printf("sum %d\n", addTwo(first, second));

return 0;

}

int addTwo(float a, float b) {

return a + b;

}

my code works but the checker does not like it so I am not sure what it is looking for

You fell in to the same mistake I did. It's quite a silly one when you look back at it. You set your arguments up correctly defining them as both floats. What you've forgotten to do (like I did) is that you've defined the function as an integer instead of a float. So whilst the arguments being taken in are floats, it's never going to return anything as a float because the function itself is an integer. This needs to be changed to a float. So, the correct code would be:

float addTwo

not:

int addTwo

I hope this makes sense!

1 Answer

Guillaume Maka
PLUS
Guillaume Maka
Courses Plus Student 10,224 Points
float addTwo(float a, float b) {
   return a + b;
}

//not need for the challenge
printf("sum %f\n", addTwo(10.0, 10.0);

and don't write the "main" function for the challenge just the "addTwo" function