GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 16-Feb-2009, 08:49
tpetsovi tpetsovi is offline
New Member
 
Join Date: Feb 2009
Posts: 7
tpetsovi has a little shameless behaviour in the past

Trying to format the output display for Fibonacci number


Heres what he's asking for and I quote " Your table must display 6 numbers per row and use a spacing of 10 for each number"

I cant seem to figure it out and my brain is fry'd from staring at it a little help would be awesome.
CPP / C++ / C Code:
#include <iostream>
#include <iomanip>
using namespace std;

void main ()
{
	int Fib1 = 0;
	int Fib2 = 1;
	int Fib3;
	int counter = 3;
	cout << setw(10) << Fib1 << setw(10) << Fib2;

	do 
	{
		Fib3 = Fib1 + Fib2;
		cout << setw(10) << Fib3;
		Fib1 = Fib2;
		Fib2 = Fib3;
		counter++;
	}
	while (counter <= 40);
		cout << endl << endl;
}




I know I could have used a for loop as well but i didn't.

also you prob already see it can only display the first 40.
Last edited by LuciWiz : 16-Feb-2009 at 09:17. Reason: Please insert your C++ between [cpp] & ]/cpp] tags
  #2  
Old 16-Feb-2009, 11:17
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 803
Howard_L is a jewel in the roughHoward_L is a jewel in the roughHoward_L is a jewel in the rough

Re: Trying to format the output display for Fibonacci number, I've tried everything.


First I must ask about:
CPP / C++ / C Code:
void main ()
{...
Does your instructor accept that? . . . I get:
Code:
g++ -Wall -W -pedantic coutformat-10.c -o coutformat-10.exe coutformat-10.c:6: error: `main' must return `int'
Instead use:
CPP / C++ / C Code:
int main()  :)
I'm not sure what your question was about specifically, but to print 6 values per row:
- Use a second: counter2 = 0;
- Inside your do-while loop: increment counter2 AND put an if( counter2 == 6 ) .
- If the if() returns true: print a newline and reset counter2 to 0 for next line.
  #3  
Old 17-Feb-2009, 00:14
ultrAslan ultrAslan is offline
New Member
 
Join Date: Feb 2009
Location: Oh, USA
Posts: 16
ultrAslan has a little shameless behaviour in the past

Re: Trying to format the output display for Fibonacci number


I was gonna mention that part too.

CPP / C++ / C Code:
void main ()
  #4  
Old 18-Feb-2009, 11:58
zalezog zalezog is offline
Junior Member
 
Join Date: Oct 2007
Posts: 33
zalezog will become famous soon enough

Re: Trying to format the output display for Fibonacci number


Actually there is no need for a
CPP / C++ / C Code:
counter2
.
Instead,
CPP / C++ / C Code:
.
.
.
if (counter % 6==0)
  //go to a new line
 counter++;
 
 

Recent GIDBlogAccepted for Ph.D. program by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
A program that calculates the number of characters in the text file et21zero Java Forum 5 28-Apr-2008 13:04
need help with a console menu system BullBuchanan C++ Forum 6 20-Aug-2006 15:46
Converting a number amount to text Godzilla C++ Forum 5 31-Mar-2006 12:38
Anyone can write a program code for this??? chriskan76 C Programming Language 1 19-Oct-2004 21:25
Apache2 config issues monev Apache Web Server Forum 2 28-Jun-2004 07:19

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 00:49.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.