# Thread: fibonacci problem

1. ## fibonacci problem

Ok so I coded the following:

Code:
```#include <iostream>
using namespace std;

int main()
{
int days, endday, pounds;
cout << "Please enter in the amount of pounds: ";
cin >> pounds;

cout << "Please enter in the days: ";
cin >> days;

cout << "Please enter the last day you want to do this calcuation: ";
cin >> endday;

int numbers=pounds;

for(int i=days;i<=endday;i=i+days)
{
if (days==i)
pounds=pounds;
else
{
pounds=pounds+(numbers/2);
numbers=pounds;
}

cout << "The day is " << i << " and the pounds are " << pounds << endl;
}
}```

But I dont get the right values for "pounds"

For instance I get :

Please enter in the amount of pounds: 10
Please enter in the days: 5
Please enter the last day you want to do this calcuation: 25
The day is 5 and the pounds are 10
The day is 10 and the pounds are 15
The day is 15 and the pounds are 22
The day is 20 and the pounds are 33
The day is 25 and the pounds are 49
Press any key to continue

what I need is day 10 to be 20, day 15, 30, day 20 to be 50 etc

Thanks for any help!

2. Sorry, but this is just wrong...

Code:
`pounds=pounds;`
Obvious statement?

Basically, there is absolutely no need to put that in the loop. Initialize pounds before the loop or inside the loop next to i, but do not initialize it to itself. That's rather rediculous.

3. The Fibonnaci sequence requires the first two variables of the sequence to be defined, and is thereafter defined as a(n) = a(n-1) + a(n-2). This is just funky.

Code:
```pounds=pounds+(numbers/2);
numbers=pounds;```

Popular pages Recent additions