# Thread: Wondering what I am doing wrong

1. ## Wondering what I am doing wrong

Ladies and Gentlemen, Here is my code:

1. //
2. //
3. //
4. //
5. //
6. // This program is used to create a function to calculate a Fibonacci number.
7.
8. #include <iostream.h>
9. #include <math.h>
10.
11. using std::cout;
12. using std::cin;
13. using std::endl;
14.
15. int fibonacci( int num3)
16.
17. int main()
18. {
19.
20. int num1, num2;
21.
22. cout << "Which fibonacci number would you like? ";
23. cin >> num1;
24. num2 = fibonacci(num1);
25. cout << "Fibonacci #" << num1 << " is " << num2 << "." << endl;
26.
27. return 0;
28. }
29.
30. int fibonacci ( int num3 )
31. {
32. int num4, count1;
33. if ( num3 < 0 )
34. num4 = -1;
35. if ( num3 == 0 ) || ( num3 == 1 )
36. num4 = 0;
37. if ( num3 > 1 )
38. {
39. count1 = 1;
40. do
41. {
42. num4 = ( count1 - 1 ) + ( count1 - 2 );
43. count1 = count1 + 1;
44. }
45. while ( count1 <= num3 );
46. return num4;
47. }

Now here are my errors:

prog_15.cpp: In function `int fibonacci(int)':
prog_15.cpp:17: parse error before `int'
prog_15.cpp: In function `int fibonacci(int)':
prog_15.cpp:31: redefinition of `int fibonacci(int)'
prog_15.cpp:17: `int fibonacci(int)' previously defined here
prog_15.cpp: In function `int fibonacci(int)':
prog_15.cpp:35: parse error before `||'
prog_15.cpp:49: parse error at end of input

Now here is my question, What am I doing wrong that is creating a parse error everytime I attempt to compile. Now mind you, I am just a college student who is new to C++ programming, with a minor background in Pascle (From about 13 years ago)

It appears to me that I have all the appropriate semi-colons or does parse error mean something more then just missing a semi-colon.

2. at least in code as posted you need another } at end of fibonacci function.

3. > 15. int fibonacci( int num3)
To make this a prototype, you need a ; on the end

> 35. if ( num3 == 0 ) || ( num3 == 1 )
This needs more ()
It should be if ( expression )

4. Thank you Thank You! And Thank you Again. 4 more eyes are deffinetly better then my 4.