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

implementing a float function

i am stuck on a challenge

1 Answer

This is what you're looking for:

float addTwo (float x, float y) {
    return x + y;
}

The first part creates a float type function named addTwo. The next part in the parentheses contains the two variables that will be fed into that function. In this case, we need two different float values, so we create two different variables for them. I called them float x and float y, but really, you can name them anything you want. Then the next part will return the summed up value of the two float variables x and y.

For example, if your function implementation looked like this, addTwo (2, 3), it would return a value sum of 5.