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

Code Compiles in Xcode but I'm told it is wrong

Please tell me what you are looking for as the correct answer as this compiles and gives me the correct answer in Xcode. I have successfully tried 4 different ways that all compiled and gave me the correct answer yet were wrong in this exercise. Thank you

float addTwoNumbers (float floatOne, float floatTwo); int main() {

float numOne = 3.2;
float numTwo = 4.3;

addTwoNumbers (numOne, numTwo);
printf("The sum of the 2 numbers is %f\n", addTwoNumbers(numOne, numTwo));

return 0 ;


float addTwoNumbers (float floatOne, float floatTwo){

float answers = floatOne + floatTwo;

return answers;


4 Answers

I wasn't very clear when I said "Your last code sample..." but what I meant was your last few lines of code is all that they want.

They only want the implementation of the function. You've written more code than what they're looking for. So they don't want the main function or printing the result of calling the function.

float addTwo (float floatOne, float floatTwo){
return floatOne + floatTwo;

Implement a function named "addTwo"...

Take a look at your function name.

Your last code sample is closest to what the code challenge wants.

Also, you don't have to assign the addition expression to a variable first and then return that variable. You can return the result of the addition directly like so: return floatOne + floatTwo;

I fixed the name of the function so it would match the assignment and am doing my addition in my return statement now. Unfortunately the Treehouse compiler didn't allow me to proceed. I REALLY appreciate any help I can get.

PS: No errors or warnings in Xcode and compiles fine.

Thanks again :P

float addTwo (float floatOne, float floatTwo);

include <stdio.h>

int main() { float numOne = 3.2; float numTwo = 4.3;

addTwo (numOne, numTwo);
printf("The sum of the 2 numbers is %f\n", addTwo(numOne, numTwo));

return 0 ;


float addTwo (float floatOne, float floatTwo){

return floatOne + floatTwo;


WOW...lol head...desk (repeat 10 times) Thank you for holding my hand and showing me.

You're welcome.