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

Can't figure out whats wrong here.

Not sure what I'm doing wrong. Please help!

functions.c
int addTwo(float a, float b);

  float numberOne = 20;
  float numberTwo = 10;

  printf("Sum is %f", addTwo(numberOne,numberTwo));  

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

3 Answers

Marileen Mennerich
Marileen Mennerich
1,161 Points

As I said, the challenge is only asking for the function, not for the whole printf-example. If you submit only the function, it should work. So only this part: float addTwo(float a, float b) { return a + b; }

Oh cool thanks! :)

Marileen Mennerich
Marileen Mennerich
1,161 Points

Code Challenges are a little finicky in what they ask for. They want you to only write down the function itself, so you might be getting an error because you did "too much".

Also, the code you pasted is a little odd. What is the first line supposed to do? You seem to be defining the function without giving it a body, then the following code is indented as if it belonged to that definition. This might confuse the compiler as well. All you need is the last 3 lines, with the return type being float instead of int.

Hey thanks for the reply but what do you mean by the return type being a float instead of an int?

Marileen Mennerich
Marileen Mennerich
1,161 Points

When I tried out the challenge, I had to define the function as "float addTwo(float a, float b)", because when you add a and b and return their sum, that sum is a float as well.

Yes but still having a problem.

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

float numberOne = 20; float numberTwo = 10;

printf("Sum is %f", addTwo(numberOne,numberTwo));