I'm trying to get this program to display the fibonacci sequence to the any digit between 3 & 30. It is stuck on an infinite loop.
here is the code I wrote:
#include <iostream>
using namespace std;
int main()
{
int num = 0;
int a = 0;
int b = 1;
int count = 0;
cout << "How many numbers do you want to run through? (3 min, 20 max) ";
cin >> num;
while ( num >= 3 && num <=20 )
{
b = a + b;
a = b - a;
b = a + b - a;
cout << b;
count = 10;
count++;
}
system ("pause");
return 0;
}
int main()
{
int num = 0;
int a = 0;
int b = 1;
int count = 0;
cout << "How many numbers do you want to run through? (3 min, 20 max) ";
cin >> num;
if(num >= 3 && num <= 20)
{
while (num > 0)
{
b = a + b;
a = b - a;
b = a + b - a;
cout << b;
count = 10;
count++;
num--;
}
}
system ("pause");
return 0;
}
Your assigning 10 to count every time it goes through the loop, then adding 1 so that it is 11. So every time this loop goes through, count is the exact same.. I don't understand the point? I also don't see where count is even used, but I imagine this isn't your full code (even though it looks like it.)
As TheNoobie said, Im not so sure about that either. Especially that you have int count = 0 outside the loop not used, and then make it 10 without even using it.