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

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

Please tell me what you are looking for as a 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;

}

2 Answers

Hi Lincoln, I tried fixing your code. The problem was the function name you were defining it as addTwoNumbers, where as the treehouse editor expects you to define it as addTwo. It expects you to define the function as what has been specifed in the function other wise it will not let you pass..... Although your code might work fine in Xcode. Here is the fix. float addTwo (float One, float Two){

float answers = One + Two; return answers; }

Also, if you define it as : float addTwo (float One, float Two){ return One+Two; } then, too it will work fine.... Why go through the pain of defining a separate variable to add the two numbers .......when you just have to return the addition...

I hope it helps you in understanding the problem.....

Got it... thank you very much for your help!!!