making Fibonacci numbers

Here is what I'm suppose to do:
By definition, the first two numbers in the Fibonacci sequence are 0 and 1, and each subsequent number is the sum of the previous two; for example, the first 6 Fibonacci numbers are 0, 1, 1, 2, 3, 5. Write a program that asks the user for a number between 5 and 20 (inclusive) and then displays that many Fibonacci numbers. You must use a loop to calculate this! Don’t just cout the answer for each of the 15 possible answers. Also: Note that there is no last comma in the list.

I can't get it to start of with 0, 1, 1,.....

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <cstdlib>
using namespace std;

int main(){
	int x = 0;
	int fibNum = 0;

	cout << "How many Fibonacci numbers do you want? <5 to 20>: ";
	cin >> fibNum;

	while(x <= fibNum){
		x = x +1;
		cout << x << ", ";
	}
	


	return 0;
}
Last edited on
Topic archived. No new replies allowed.