Fibunacci Calculator

New Member
Joined
Oct 15, 2006
Messages
23
Best answers
0
Something (I'm not sure what...) gave me the idea to create a calculator that can find any number in the Fibunacci series. I've been working on this for a while now, and it's finally finished. I'm posting it here for review, comments and criticism. I'll post the source code later as well.

http://**********.com/files/9211193/Fib.zip.html - For some reason, the word R-a-p-i-d-s-h-a-r-e is filtered...

Usage: Enter a number in the Fibunacci series, and the program will find it's value. For those of you uneducated folks, here's an example of the Fibunacci series to give you an idea:

The 1st number in the Fibunacci series is 1. The 2nd number in the Fibunacci series is 1 as well. The 3rd number in the Fibunacci series is the sum of numbers 1 and 2, which is 2. The 4th number in the Fibunacci series is the sum of numbers 2 and 3, which is 3. The 5th number in the Fibunacci series is the sum of numbers 3 and 4, which is 5. Got an idea for it yet? Good.

Tell me what you think. I'll post the source later on.

P.S. I realize that this has absolutely nothing to do with bugs in ESF, but it seemed like a reasonable place to put it.
 
Cunning as Zeus
Banned
✔️ HL Verified
💻 Oldtimer
Joined
Nov 23, 2003
Messages
6,079
Best answers
0
Just so you know, it's spelled Fibonacci.
 
Lost in space
Banned
💻 Oldtimer
Joined
Sep 20, 2003
Messages
3,211
Best answers
0
It's not hard, there's a mathematical formula for it =/ 5C3 OMG!

So yeah, but hey you created it, which is more than what I can do (i can balance a pencil inside my fist) so grats.
 
New Member
Joined
Oct 15, 2006
Messages
23
Best answers
0
Source:
Code:
/*****************************************
*           XENON PRESENTS               *
*      The Fibonacci Calculator          *
*            Version 1.0.1               *
*****************************************/
#include iostream // Add the < and > yourself. It won't show up in CODE tags...

using std::cout;
using std::cin;

unsigned long int fib (unsigned long int n);

int main()
{
    unsigned long int n;
    int answer;
    
    cout << "Enter number to find: ";
    cin >> n;
    
    cout << "\n";
    
    answer = fib(n);
    
    cout << answer << " is the " << n;
    cout << "th Fibonacci number.\n";
    
    cin.get();
    cin.ignore();
    
    return 0;
}
unsigned long int fib (unsigned long int n)
{
         cout << "Processing fib(" << n << ")... ";
         
         if (n < 3)
         {
               cout << "Return 1!\n";
               return (1);
         }
         else
         {
             cout << "Call fib(" << n-2 << ") ";
             cout << "and fib(" << n-1 << ").\n";
             return (fib(n-2) + fib(n-1));
         }
}
Enjoy. Also, any advice would be great. I'm still learning, and this is what I can do with what I know, but I'm learning extremely fast.
 
New Member
Joined
Apr 23, 2005
Messages
890
Best answers
0
You could do all of this with Excel easily... But nice work anyway. Good for improving you programming skills.
 
New Member
Joined
Oct 15, 2006
Messages
23
Best answers
0
Jariroth said:
You could do all of this with Excel easily... But nice work anyway. Good for improving you programming skills.
This isn't Excel, it's C++. And it was probably just as easy as with Excel.

But thanks for the somewhat constructive comments.
 
New Member
Joined
Nov 24, 2001
Messages
692
Best answers
0
Cool, now it would be a good training to eliminate recursion and do the same in a loop. Also, note that to calculate fib(n-1), you have to calculate fib(n-2) first, so you're doing some double work.
 
New Member
Joined
Oct 15, 2006
Messages
23
Best answers
0
harSens said:
Cool, now it would be a good training to eliminate recursion and do the same in a loop. Also, note that to calculate fib(n-1), you have to calculate fib(n-2) first, so you're doing some double work.
I haven't read about looping yet. I'm getting there though. Right now, I'm focused on trying to make good use of recursion.
 
New Member
💻 Oldtimer
Joined
Apr 8, 2004
Messages
1,003
Best answers
0
harSens said:
Cool, now it would be a good training to eliminate recursion and do the same in a loop. Also, note that to calculate fib(n-1), you have to calculate fib(n-2) first, so you're doing some double work.
I've never thought about that. Changing a single line of code would make it much more efficient, without changing the result of the calculation.

Never met anyone who learned recursion before loops, but I guess everyone has a choice.
Have you ever programmed in another language before?
 
New Member
Joined
Oct 15, 2006
Messages
23
Best answers
0
Orbit said:
I've never thought about that. Changing a single line of code would make it much more efficient, without changing the result of the calculation.

Never met anyone who learned recursion before loops, but I guess everyone has a choice.
Have you ever programmed in another language before?
No, I haven't. C++ is my first language, although I've had experience with other languages (making simple value changes to scripts in C#, for example). But I'd never actually programmed anything until about a week ago.
 
New Member
💻 Oldtimer
Joined
Apr 8, 2004
Messages
1,003
Best answers
0
Xenon said:
No, I haven't. C++ is my first language, although I've had experience with other languages (making simple value changes to scripts in C#, for example). But I'd never actually programmed anything until about a week ago.
C++ was my first language as well. If you wish to try something a bit more advanced in recursion, create a program which solves the Towers of Hanoi puzzle.
 
New Member
Joined
Oct 15, 2006
Messages
23
Best answers
0
frsrblch said:
Not bad. What was your motivation for undertaking this little endeavor? Are you teaching yourself how to program?

A 4th year CompEng I know had to make a program that solves Sudoku. So sure, programming is neat and fun at the beginning, but it quickly grows to be a pain. Just thinking about that guy spending hours debugging pages and pages of code makes me cringe.

Any chance of me liking programming was crushed by my first year CompEng class. It's not that I don't enjoy making programs that find prime numbers, but to have to spend a couple hours on something so useless every single week is irritating.
Believe me, I know how you feel. But it's all part of the learning process.
 

Users who are viewing this thread

Top Bottom