I've created a function that calculates a fibonacci number by calling itself, however, the programme always returns 1 instead of 0 when I type in 0, so the else-statement of my if-loop doesn't work. Apart from that the programme does what I expected.
This is my programme:
#include <iostream>
long long fibonacci (long long a)
{
if (a>=3)
return (fibonacci(a-1)+fibonacci(a-2));
else if (1<=a<=2)
return (1);
else
return (0);
}
int main ()
{ long long b;
std::cout << "Geben Sie ein, die wievielte Fibonaccizahl Sie berechnen lassen wollen.\n";
std::cin>>b;
std::cout<<"Die "<<b<<"te Fibonaccizahl lautet "<<fibonacci(b)<<".\n";
return 0;
}