Help regarding formatting for a Fibonacci Sequencing Program

closed account (N13pfSEw)
I basically have the whole thing written, and it works perfectly, but my professor is asking us to have six values per row, and my values are being outputted into one column. Is there anyone who can help with that?

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
#include <iostream>
#include <iomanip>

using namespace std;

int main()
{

	cout <<"This program gives the user the desired amount of Fibonacci numbers \n";

	int x, y, a = 0, b = 1, next;

	cout << "Please enter the number of Fibonacci terms you want: ";

	cin >> x;


	cout << "The first " << x << " terms of the series are: ";

	for (y = 0; y < x; y++)
	{ 
		if ( y <=1 )
			next = y;
		else 
		{
			next = a + b;
			a = b;
			b = next;
		}

	
		cout << next;
	}


	return 0;
}
You claim to get a column, yet you print no endline characters. If you would add the endline only so often, ...
closed account (N13pfSEw)
I'm new at this, where should the endl; go?
hi.
here's my advice:
remove line 32, and place these lines instead:
1
2
3
    cout<<next<<'\t';
    if( ! (y%6) )
        cout<<endl;


hope you understand the if statement.
Last edited on
Topic archived. No new replies allowed.