O
O
Old Odessa2015-11-25 23:17:39
Programming
Old Odessa, 2015-11-25 23:17:39

Why doesn't the program work, c++ fibonacci?

#include <iostream>
using namespace std;
int fibonacci(int n)
{
    if (n == 0) return 0;
    else if (n==1 && n==2) return 1;
    else return fibonacci(n-1)+fibonacci(n-2);
    }
int n;
int main(){
    cout<<"Wprowadz numer liczbe"<<endl;
    cin >> n;
    cout << "Liczba Fibonacci numerowane "<< n <<" jest " << fibonacci(n) << endl;
    return 0;
}

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
metallix, 2015-11-26
@vs_convoy

else if (n==1 && n==2) return 1;
"n" in two states at once? o_o

V
Vladimir Martyanov, 2015-11-25
@vilgeforce

It doesn't work because you are not using a debugger. Until you learn how to use a debugger, you won't be able to write programs harder than "Hello world" yourself.

S
SpyceR, 2015-11-25
@SpyceR

Let's start with the fact that the error here is even in the first line.

#include //что?
....
else if (n==1 && n==2) return 1; //здесь должно быть "или", а не "и" (это и есть проблема функции)
....
cout<<"Wprowadz numer liczbe"<> n;
//Что, по вашему, оно должно делать?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question