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

Stuck on Challenge Task - Functional Programming in C

I'm stumped on this one ...

Write a function named "addTwo" that accepts two float numbers as arguments. The function should also return a float which is the sum of the two arguments passed to the function.

Here's the code I wrote ...

float addTwo(float a, float b);
int main() 
{

    float one = 2.5;
  float two = 10.5;

  float sum = addTwo(one, two);
  printf("The sum of one and two is %f\n", sum);

  return 0;

}

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

 }

When I run this in Xcode it works fine, but the challenge screen comes back with this when I preview it ...

conflicting types for 'main' int main(int argc, const char * argv[]) ^ note: previous definition is here int main() ^ 1 error generated.

I have had trouble in the past understanding some of the questions because half the time I don't know how much of the actual code is required to satisfy the question. My understanding is that the source code will always include an int main() function block.

Any guidance would be greatly appreciated ... Scott

1 Answer

I was able to find the answer in this question (sorry I should have checked the forum more thoroughly for the same question) https://teamtreehouse.com/forum/functions-code-challenge-3

This brings up what I mentioned at the end of my question. I seem to take the questions too literally, as in the code that satisfied the answer would not have worked without the rest of it. Hopefully I'll get the hang of reading the questions for what they need, and not reading too much into them. I was never good at story problem solving in school, which these questions remind me of HA!