Can someone please read the following assignment and look at the code I've completed and tell me if it is correct before I submit it to my professor? Immediate help would be great if possible.
Here's the assignment -
The Fibonacci sequence consists of the numbers 1,1,2,3,5,8,13 ...... in which each number (except the first 2) is the sum of the two preceding numbers. This means that:
Assume that Fib(0)=1
Assume that Fib(1)=1
Then Fib(2)=Fib(0) + Fib(1)=1+1=2
Also Fib(3)= Fib(1)+Fib(2)=1+2=3
Also Fib(4)=Fib(2)+Fib(3)=2+3=5
Also Fib(5)=Fib(3)+Fib(4)=3+5=8
Write a header file which that you will call Fibonacci.h. The file contains a recursive method Fib with one parameter of type long and returns the Fibonacci value. Remember to use long as a data type for the returned fibonacci result by the method Fib because the number could be very large.
Write a C++ file that reads in a long number and returns the corresponding Fibonacci number. Remember to limit the number you read in to a value between 0 and 40.
And here's my coding for both files
(header file)
cpp
#include <iostream>
using namespace std;
int fib(int num)
{
if (num <= 1) {
return 1;
} else {
return fib(num-1)+fib(num-2);
}
}
(cpp file)
cpp
#include <iostream>
#include <cmath>
#include <iomanip>
#include "Fibonacci.h"
using namespace std;
//int Fibonacci(int, int, int);
int main()
{
cout << " enter a number" << endl;
int num;
cin >> num;
cout << fib(num) << endl;
cin.get();
return 0;
}
** Edit **