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

Float?

This is the question I've been given:

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 don't understand what it means by 'add two float'.

Please help!

3 Answers

So you are creating a function that adds two floats together like this:

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

So the float named "addTwo" is made of two variables, float x and float y. You then return a result which adds these two floats together.

So if x = 2 and y = 3 (They are the floats) the result that is returned will be x + y or 2 + 3 which = 5

Hope that helps...

Soojin Ro
Soojin Ro
13,331 Points

"float" in the question is referring to float-type variables. "Float" is a primitive data type, just like "int", that is used to represent decimals. FYI, it is called 'float' because of the way computer handles decimal numbers as binary data. Decimal point floats around numbers. Its location is not fixed.

Thank you so much! I finally passed it.