3 Replies - 284 Views - Last Post: 22 May 2013 - 10:40 PM Rate Topic: -----

#1 roberttavares92  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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  Icon User is offline

  • D.I.C Head

Reputation: 21
  • View blog
  • 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

Was This Post Helpful? 1
  • +
  • -

#3 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 810
  • View blog
  • Posts: 2,405
  • Joined: 20-March 10

Re: how to loop

Posted 22 May 2013 - 10:37 PM

Scratch that answered by buffallobil

Snoopy.

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

Was This Post Helpful? 0
  • +
  • -

#4 roberttavares92  Icon User is offline

  • New D.I.C Head

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

Re: how to loop

Posted 22 May 2013 - 10:40 PM

View Postbuffalobill, 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!

View Postsnoopy11, on 23 May 2013 - 12:37 AM, said:

Scratch that answered by buffallobil

Snoopy.


Appreciate the help anyways, Thanks!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1