P
Protoman
This Fibonacci program prints the wrong value for phi; it should be
1.618..., not 1. And it halts and closes as soon as I execute it.
Code:
#include <iostream>
#include <iomanip>
#include <cstdlib>
#define setprec setprecision
using namespace std;
template <long long N> class FIB
{
public:
const static long long RET=FIB<N-1>::RET+FIB<N-2>::RET;
};
template<>class FIB<2>
{
public:
const static long long RET=1;
};
template<>class FIB<1>
{
public:
const static long long RET=1;
};
template<>class FIB<0>
{
public:
const static long long RET=0;
};
long double phi=FIB<10>::RET/FIB<9>::RET;
int main()
{
cout << "Fib(30)=" << setprec(10) << fixed << FIB<10>::RET << endl;
cout << "Fib(29)=" << setprec(9) << fixed << FIB<9>::RET << endl;
cout << "Phi= " << setprec(30) << fixed << phi << endl;
system ("PAUSED");
return 0;
}
Any guesses as to what's wrong, b/c I can't detect any errors?
Thanks!!!!
1.618..., not 1. And it halts and closes as soon as I execute it.
Code:
#include <iostream>
#include <iomanip>
#include <cstdlib>
#define setprec setprecision
using namespace std;
template <long long N> class FIB
{
public:
const static long long RET=FIB<N-1>::RET+FIB<N-2>::RET;
};
template<>class FIB<2>
{
public:
const static long long RET=1;
};
template<>class FIB<1>
{
public:
const static long long RET=1;
};
template<>class FIB<0>
{
public:
const static long long RET=0;
};
long double phi=FIB<10>::RET/FIB<9>::RET;
int main()
{
cout << "Fib(30)=" << setprec(10) << fixed << FIB<10>::RET << endl;
cout << "Fib(29)=" << setprec(9) << fixed << FIB<9>::RET << endl;
cout << "Phi= " << setprec(30) << fixed << phi << endl;
system ("PAUSED");
return 0;
}
Any guesses as to what's wrong, b/c I can't detect any errors?
Thanks!!!!