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;
}
}