I've ran into a problem :(
Something is wrong between my functions. When I try to take 'num' from the main function and put it in the getFib() function, it turns into some crazy number, sometimes random. Why wont it stay the same number that was declared in main?
Sorry I know its a mess, it was nice and neat until I tore into it trying to find the problem. I placed some cout statements for debugging but no luck.
Any help would be appreciated, thank you.
#include <iostream>
using namespace std;
long double getFib(long double);
int main()
{
long double num = 98;
while ( num < 0 || num > 97 )
{
cout << "Which Fibonacci Number Would You Like? ";
cin >> num;
}
long double b;
getFib(b);
cout << "Cout Num:" << num << endl;
cout << "Fibonacci #" << num << " is " << b;
system ("pause");
return 0;
}
long double getFib(long double num)
{
long double a = 0, b = 1, c=0;
cout << "Num: " << num << endl;
cout << "Before: " << a << b << c <<endl;
for (long double i = 0; i <= num; i++)
{
long double c = a + b;
a = b;
b = c;
}
cout << "After: " << a << b << c << endl;
return b;
}