943,981 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 5694
  • C RSS
Apr 8th, 2007
0

Having problem generating Fibonacci sequence

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

Here is my program:
#include <iostream>
#include <conio>
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?
Reputation Points: 24
Solved Threads: 0
Light Poster
naya22 is offline Offline
48 posts
since Apr 2007
Apr 8th, 2007
0

Re: Having problem generating Fibonacci sequence

Did you write that yourself?
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Apr 8th, 2007
0

Re: Having problem generating Fibonacci sequence

I'm sorry...It's not really my program.
Reputation Points: 24
Solved Threads: 0
Light Poster
naya22 is offline Offline
48 posts
since Apr 2007
Apr 8th, 2007
0

Re: Having problem generating Fibonacci sequence

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.
Last edited by iamthwee; Apr 8th, 2007 at 11:08 am.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Apr 8th, 2007
0

Re: Having problem generating Fibonacci sequence

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.
Reputation Points: 24
Solved Threads: 0
Light Poster
naya22 is offline Offline
48 posts
since Apr 2007
Apr 10th, 2007
0

Re: Having problem generating Fibonacci sequence

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<n;i++)
{
i=i+i+1;
printf("%d",& num)
}
// this will generate the remaining fib series from 30 onwards until where u want thats by specifying the value of n!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jimmymerchant is offline Offline
3 posts
since Apr 2007
Apr 27th, 2007
0

Re: Having problem generating Fibonacci sequence

So, how do I get the user to specify the value of N??
Reputation Points: 24
Solved Threads: 0
Light Poster
naya22 is offline Offline
48 posts
since Apr 2007
Apr 27th, 2007
0

Re: Having problem generating Fibonacci sequence

this way:
  1. int N;
  2. cout<<"Please input n";
  3. cin>>N;
  4. for(j=0;j<N;j++){
  5. temp=temp+temp+1)
  6. }for(i=temp;i<n;i++){
  7. i=i+i+1;
  8. cout>>num;
  9. }
hope u don't mind i used ur code jimmymerchant...

but that's the way it will work with an user input...
Featured Poster
Reputation Points: 424
Solved Threads: 57
Posting Virtuoso
Nichito is offline Offline
1,594 posts
since Mar 2007
Apr 27th, 2007
0

Re: Having problem generating Fibonacci sequence

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
Reputation Points: 15
Solved Threads: 4
Posting Pro
anupam_smart is offline Offline
598 posts
since Feb 2006
Apr 27th, 2007
0

Re: Having problem generating Fibonacci sequence

sorry about that...
Featured Poster
Reputation Points: 424
Solved Threads: 57
Posting Virtuoso
Nichito is offline Offline
1,594 posts
since Mar 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: removing an element...
Next Thread in C Forum Timeline: C array I/O





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC