# how to loop

Page 1 of 1

## 3 Replies - 419 Views - Last Post: 22 May 2013 - 10:40 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=321643&amp;s=ec55d69d6be6ea39aa0b3e1211363b80&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 roberttavares92

Reputation: 0
• Posts: 9
• Joined: 22-May 13

# how to loop

Posted 22 May 2013 - 10:13 PM

Does anyone have anyway of looping this program to start a new line every 6 numbers, I have tried many different ways, but none seem to consistently break a new line after every 6 numbers in a Fibonacci series. Here is what I have so far:

```#include <iostream>
#include <iomanip>
using namespace std;

int main()

{
int a=0;
int b=1;
int c;
int n;
int i;

cout << "How many numbers in the Fibonnaci series do you wish to see: ";
cin >> n;
cout << '\n';

for (i=0; i<n; ++i)

{

if(i<=1)
{
c=i;
}
else
{
c=a+b;
a=b;
b=c;
}

cout << setw(5) << c;

}

cout << '\n';

return 0;
}

```

Thanks!

Is This A Good Question/Topic? 0

## Replies To: how to loop

### #2 buffalobill

Reputation: 21
• Posts: 188
• Joined: 08-July 08

## Re: how to loop

Posted 22 May 2013 - 10:30 PM

You could try something like this:
```if(i%6==0)cout<<"\n";//at line 23
```

### #3 snoopy11

• Engineering ● Software

Reputation: 1073
• Posts: 3,203
• Joined: 20-March 10

## Re: how to loop

Posted 22 May 2013 - 10:37 PM

Snoopy.

This post has been edited by snoopy11: 22 May 2013 - 10:39 PM

### #4 roberttavares92

Reputation: 0
• Posts: 9
• Joined: 22-May 13

## Re: how to loop

Posted 22 May 2013 - 10:40 PM

buffalobill, on 23 May 2013 - 12:30 AM, said:

You could try something like this:
```if(i%6==0)cout<<"\n";//at line 23
```

I tried that code before, but in a different line. Your way worked, thanks very much!

snoopy11, on 23 May 2013 - 12:37 AM, said: