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

Pierre Fatal
Pierre Fatal
3,727 Points

This is the best that I could come up with. Any suggestions? Mostly guessing at this point.

include <stdio.h>

float addTwo[] = {1.2, 1.3}; {

addTwo[] = {1.2, 1.3};
float fa = 1.2 + 1.3;
printf("fa %f\n", fa);

float addTwo[] = {1.2, 1.3}; {
    return 1.2 + 1.3;
}

2 Answers

Stone Preston
Stone Preston
42,016 Points

all you need to do is implement the function. nothing else. it should look something like this:

returnType functionName(datatype argumentOne, datatype argumentTwo) {

       return something;
}

in this case the return type needs to be a float, the function name is addTwo, you need two float arguments, and you need to return the sum of those arguments in the body of the function.

//initiate function
float addTwo(float one, float two);

int main(){
//create array
float addTwo[] = {1.2, 1.3};

//use function
addTwo(addTwo[0], addTwo[1]);

//print out result
printf("fa %f \n", fa);
}

//create actual function
float addTwo(float one, float two){
      sum = one + two;
      return sum;
}