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
Scott Taylor
7,089 PointsFunctional Programming in C - Challenge
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.
I'm not sure what I'm doing wrong, this is what I have:
int addTwo(int a, int b);
int main() {
int foo = 1.2224;
int bar = 4.3246;
printf("%f\n", addTwo(foo,bar));
return 0;
}
int addTwo(int a, int b) {
return a + b;
}
Any help would be greatly appreciated.
2 Answers
Scott Taylor
7,089 PointsSorry just found this on Google:
https://teamtreehouse.com/forum/trouble-with-floats-and-functions-in-c
RASHU BHATNAGAR
Courses Plus Student 2,669 PointsHi , I dont know if you still need any help but could not stop myself from replying.... The things which i found in your code which might not match what the editor expects: int addTwo(int a, int b);
The return type should be float. so you should write float addTwo(float a, float b) both in the declaration and definition.
int main( ) { int foo = 1.2224; int bar = 4.3246;
main is not required to be added. even if you are doing it in xcode then too no extra main ( ) is required as the xcode editor will already have it added for you when you in the command line tool.
foo and bar are expected to be float values so, you should write float foo = 1.2224; float bar = 4.3246;
I hope it helps....