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

Y. Kravets
Y. Kravets
10,350 Points

What am I doing wrong?

I keep getting the following message: "Bummer! The function does not appear to be returning the correct value. Is the return type a float?"

As you can clearly see I have defined the resulting variable to be a float type - what am I doing wrong?

functions.c
int addTwo(float a, float b)
{
  float sum;
  sum = a + b;
  return sum;
}

5 Answers

Juan Martinez
Juan Martinez
1,031 Points

If this is from the question on the quiz after the video then the answer should look like this

float addTwo(float a, float b);

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

the float at the beginning of the function is saying that the function will be returning a float value

ask a question get a question ?

int addTwo(float a, float b) <---- what is the purpose of int here

You have "int" at beginning of function definition this specifies a return type

is the caller of this function expecting an int ?

Y. Kravets
Y. Kravets
10,350 Points

I was under impression that this is how you define a function. Am I wrong?

Y. Kravets
Y. Kravets
10,350 Points

No it does not, but whenever I specify ```int addTwo(float a, float b)''' it doesn't work either, which is why I am a bit lost.