HELP!!!

create a program that display all the fibonacci numbers and display the 21st digit using array.

here's my code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
using namespace std;

int main () {

		


		cout<<" This program shows a series of fibonacci numbers \n\n\n"<<endl;
					cout<<"-------------------------------"<<endl;


		int n=0;
		int fnum;
		int counter=-1;


while  (n<=20)  {

	if (n==1){

		fnum=1;
		counter=counter+1;
	}

	while (n>1){
		
	fnum=(n-1)+(n+1);
	counter=counter+1;
	}
	


	}

	cout<<fnum<<endl;


	if (n==0){
		 fnum=0;
		 counter=counter+1;
	}



		return 0;
Does the code not work or something? What's the problem? (Besides the horrid indentation...)
i believe you are overthinking the problem. Maybe something more like this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
        int num1 = 0;
	int num2 = 1;

	cout << num1 << endl;
	cout << num2 << endl;
	
	
	//Fibonacci numbers are 0, 1, 1, 2, 3, 5, 8, 13, 21
	while (num1 < 10)
	{
		num1 = num1 + num2;
		num2 = num1 + num2;
		
		if (num1 > 21)
		{
			break;
		}
		cout << num1 << endl;
		
		if (num2 > 21)
		{
			break;
		}
		cout << num2 << endl;
		
	
	}
Topic archived. No new replies allowed.