954,206 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Having problem generating Fibonacci sequence

I am having problems generating the Fibonacci sequence. I would like to start at 30.

Here is my program:
#include
#include
using namespace std;
int main()
{
int Fibonacci, n;
cout <<"Here is the Fibonacci number sequence until 30 .";
if ( n==1 || n==2 )
return( 1 );
else
cout << Fibonacci(n-1) + Fibonacci(n-2);
getch();
return 0;
}

However, I am getting an error message where the statement is in bold. It is telling me that it is a call of nonfunction.

What am I doing wrong here?

naya22
Light Poster
48 posts since Apr 2007
Reputation Points: 24
Solved Threads: 0
 

Did you write that yourself?

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

I'm sorry...It's not really my program.

naya22
Light Poster
48 posts since Apr 2007
Reputation Points: 24
Solved Threads: 0
 

Wanna know how I knew that. You have a function but with no actual declaration of it. (no Sh*t sherlock!)

Word of advice. Don't try cheating. Try it yourself from the beginning. You'll get a lot more out of it.

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

okay, okay, don't get hostile. I'll try it myself and come back. I really do apologize though, for trying to take the easy way out.

naya22
Light Poster
48 posts since Apr 2007
Reputation Points: 24
Solved Threads: 0
 

hey its easy to generate a fib series, it just adds the prev 2 nos and then get the third one.
so u cud have for loop to generate it as follows
for(j=0;j<30;j++)
{temp=temp+temp+1)
}
//this generates the fib series till 30
for(i=temp;i

jimmymerchant
Newbie Poster
3 posts since Apr 2007
Reputation Points: 10
Solved Threads: 0
 

So, how do I get the user to specify the value of N??

naya22
Light Poster
48 posts since Apr 2007
Reputation Points: 24
Solved Threads: 0
 

this way:

int N;
cout<<"Please input n";
cin>>N;
for(j=0;j<N;j++){
   temp=temp+temp+1)
}for(i=temp;i<n;i++){
   i=i+i+1; 
   cout>>num;
}

hope u don't mind i used ur code jimmymerchant...

but that's the way it will work with an user input...

Nichito
Posting Virtuoso
1,602 posts since Mar 2007
Reputation Points: 424
Solved Threads: 57
 

Well,
What's gonin' on here guys..
I thought the rule here is to correct an existing code instead of providing a completly new one.
-Must take care of this...
Thanks

anupam_smart
Posting Pro
599 posts since Feb 2006
Reputation Points: 15
Solved Threads: 4
 

sorry about that... :D

Nichito
Posting Virtuoso
1,602 posts since Mar 2007
Reputation Points: 424
Solved Threads: 57
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You