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

Blaine Fallis
Blaine Fallis
2,449 Points

challenge 1 functions

hello y'all. I'm not completing this challenge correctly:

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

Here's what I've put down so far:

float addTwo(float a, float b);

{ float num1 = 12.6; float num2 = 15.4;

float theSUM = addTwo(num1, num2);

}

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

I'm looking for a tip to push me in the right direction. I didn't put in a print statement. The error I get is: Bummer! Make sure you've defined the return type and both paramter types as 'float' and that you are returning the sum of the arguments as a result.

3 Answers

Ben Falk
Ben Falk
3,167 Points

Based on how I read the question, you just have to write the function itself. You shouldn't need to define what each float value is, or actually call that function, in order to complete the challenge.

Stone Preston
Stone Preston
42,016 Points

all you need is this:

float addTwo(float a, float b) { return a + b; }
Blaine Fallis
Blaine Fallis
2,449 Points

thank you. I like the challenge thing because you have to stumble around a bit sometimes looking for answers which leads to new discoveries. e.g. I learned that the word float is used to declare a float function so I guess there's float, char, int and probably others.

Also besides %c and %d for char and int, there is a %f to output a float, and probably others? %s Anyway I've a long ways to go but having fun. Amazing that the C++ class I had 15 years ago is still applicable.