1.) This program does not compile; so you are not even at the step where you can see what logic problems you have.
2.) stop -- test each function individually to ensure they compile and return what you expect.
3.) When you have a problem with a specific function; either why it won't compile or why it is doing something other than what you expected--post that question.
4.) It is always best to break big problems into little ones first.