Wondering what I am doing wrong

This is a discussion on Wondering what I am doing wrong within the C++ Programming forums, part of the General Programming Boards category; Ladies and Gentlemen, Here is my code: 1. // 2. // 3. // 4. // 5. // 6. // This ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    34

    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.
    http://members.ebay.com/aboutme/the_ski/

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

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,451
    > 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 )
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    34
    Thank you Thank You! And Thank you Again. 4 more eyes are deffinetly better then my 4.
    http://members.ebay.com/aboutme/the_ski/

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Debugging-Looking in the wrong places
    By JaWiB in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 11-03-2003, 09:50 PM
  2. Confused: What is wrong with void??
    By Machewy in forum C++ Programming
    Replies: 19
    Last Post: 04-15-2003, 12:40 PM
  3. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 11:01 AM
  4. Whats wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 07-14-2002, 01:04 PM
  5. What did i do wrong? Code inside
    By The Rookie in forum C Programming
    Replies: 2
    Last Post: 05-18-2002, 08:14 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21