Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Objective-C Basics (Retired) Functional Programming in C Functions

FLOAT..!! it is not accepting my code, and I don't get what I'm doing wrong...

well, I've tried everything, and maybe it's just that I'm not quite understanding what I'm being asked for (English is not my first language...)

this is what they are asking:

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

I'll paste my code down here and if you could help me out a little I would seriously appreciate it.

float addTwo (float a, float b);
    float a = 24;
    float b = 35;

    float result = a + b;
    printf("a + b = %f\n", result);

    return a + b;

thanks a lot...!!

2 Answers

You just need to implement the function, not add parameters to it or anything like that. And remember, the body of a function must be surrounded in curly braces:

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

thanks a lot, I was just complicating myself after having tried so many different things...

Robert Bojor
PLUS
Robert Bojor
Courses Plus Student 29,439 Points

Hello,

You need to write a function that will add the two passed parameters. Something like this:

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

and then just call addTwo(1.2, 2.1);

thanks a lot, I was just complicating myself after having tried so many different things...