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

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.