Fibonacci Help

I am trying to write a program that prompts the user for a number and then shows that many Fib numbers aka(you answer 3, it shows 0 1 1). I am wanting to use a for loop to do this. Just learned for loops so thats why I need help. Here is the code. It works in a way.

#include <iostream>
using namespace std;
int main()
{
int fib1=0, fib2=1, number, fibanswer;
cout << "How many Fibonacci numbers do you want? ";
cin >> number;
if (number == 1)
{
cout << fib1 << endl;
}
else if (number > 1)
{
cout << fib1 << " " << fib2 << endl;
}
for (int x = 0; x < number + 2; x = x++)
{
fibanswer = fib1 + fib2;
fib1 = fib2;
fib2 = fibanswer;
cout << fibanswer << endl;
}
}

It works, doesn't it?

I'm confused why you do set the range to "number + 2". If you want fib(3) to print "0 1 1", then it should stop at "number".
Look here at my code

http://www.cplusplus.com/forum/beginner/74609/
Topic archived. No new replies allowed.