User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 402,053 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,438 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 398 | Replies: 13 | Solved
Reply
Join Date: May 2008
Posts: 96
Reputation: QuantNeeds is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
QuantNeeds QuantNeeds is offline Offline
Junior Poster in Training

help formatting

  #1  
Jul 7th, 2008
Hello,

The following code works but I am having trouble formatting it with setw() and I am not sure if it possible to format it with a space so that the entire seat header fits on one line and for the rows to also fit on one line with spaces.

My code is the following:

void Tickets::displaySeats()
{
	cout << "Seats: ";
	int counter = 1;

	do
	{
		cout << counter << " ";
	}while(++counter <= 30);

	for(int row_i = 1; row_i < row; row_i++)
	{
		cout << "\nrow " << row_i << ": ";
		for (int seat_j = 1; seat_j < seat; seat_j++)
		cout << seating[row_i][seat_j] << " ";
	}
}
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2007
Posts: 232
Reputation: joshmo is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 19
joshmo joshmo is offline Offline
Posting Whiz in Training

Re: help formatting

  #2  
Jul 7th, 2008
What kind of problem are u experiencing with setw()? Did you add the header file "iomanip"?
Reply With Quote  
Join Date: May 2008
Posts: 96
Reputation: QuantNeeds is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
QuantNeeds QuantNeeds is offline Offline
Junior Poster in Training

Re: help formatting

  #3  
Jul 7th, 2008
Originally Posted by joshmo View Post
What kind of problem are u experiencing with setw()? Did you add the header file "iomanip"?


yep - I just can't get them all in one line using setw()
Reply With Quote  
Join Date: Sep 2004
Posts: 6,065
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 26
Solved Threads: 419
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

Re: help formatting

  #4  
Jul 7th, 2008
>I just can't get them all in one line using setw()
Show us your code that uses setw, an example of the output you're expecting, and an example of the output you actually get.
I'm a programmer. My attitude starts with arrogance, holds steady at condescension, and ends with hostility. Get used to it.
Reply With Quote  
Join Date: May 2008
Posts: 96
Reputation: QuantNeeds is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
QuantNeeds QuantNeeds is offline Offline
Junior Poster in Training

Re: help formatting

  #5  
Jul 7th, 2008
Originally Posted by Narue View Post
>I just can't get them all in one line using setw()
Show us your code that uses setw, an example of the output you're expecting, and an example of the output you actually get.


Well I changed it and now I am getting everything to work except for 10-30 on the header. I need a space, but when I try to say the following in the "do loop", it does not work and it makes the header go down to a second line:

if(counter <= 9)
      cout << counter << setw(2);
else
      cout << " " << counter;
}while(++counter <= 30);


Is there a way to expand the actual command prompt?

My updated code is the following:

void Tickets::displaySeats()
{
	// creater the header
	cout << "Seats: " << setw(2);
	int counter = 1;
	do
	{
		if(counter <= 9)
			cout << counter << setw(2);
		else
			cout << counter << setw(1);
	}while(++counter <= 30);

	// show the seat availability
	for(int row_i = 1; row_i < row; row_i++)
	{
		if(row_i <= 9)
		{
			cout << "\nrow 0" << row_i << ": ";
		}
		else
		{
			cout << "\nrow " << row_i << ": ";
		}

		for (int seat_j = 1; seat_j < seat; seat_j++)
		cout << seating[row_i][seat_j] << " ";
	}
}
Reply With Quote  
Join Date: Sep 2004
Posts: 6,065
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 26
Solved Threads: 419
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

Re: help formatting

  #6  
Jul 7th, 2008
>it does not work and it makes the header go down to a second line
Unless you're actually printing a newline character somewhere, the problem is your console window isn't wide enough and wraps around. Try redirecting your output to a file and I'd be willing to bet that it looks just fine.

>Is there a way to expand the actual command prompt?
Not that I know of, at least not without delving into the realm of creating your own windows.
I'm a programmer. My attitude starts with arrogance, holds steady at condescension, and ends with hostility. Get used to it.
Reply With Quote  
Join Date: May 2008
Posts: 96
Reputation: QuantNeeds is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
QuantNeeds QuantNeeds is offline Offline
Junior Poster in Training

Re: help formatting

  #7  
Jul 7th, 2008
Originally Posted by Narue View Post
>it does not work and it makes the header go down to a second line
Unless you're actually printing a newline character somewhere, the problem is your console window isn't wide enough and wraps around. Try redirecting your output to a file and I'd be willing to bet that it looks just fine.

>Is there a way to expand the actual command prompt?
Not that I know of, at least not without delving into the realm of creating your own windows.


so i can't fix this?
Reply With Quote  
Join Date: Sep 2004
Posts: 6,065
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 26
Solved Threads: 419
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

Re: help formatting

  #8  
Jul 7th, 2008
>so i can't fix this?
It's hard to fix something that isn't broken. If you don't like the current result, change your formatting to better suit the display medium, or change the display medium to something better suited for your formatting.
I'm a programmer. My attitude starts with arrogance, holds steady at condescension, and ends with hostility. Get used to it.
Reply With Quote  
Join Date: May 2008
Posts: 96
Reputation: QuantNeeds is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
QuantNeeds QuantNeeds is offline Offline
Junior Poster in Training

Re: help formatting

  #9  
Jul 7th, 2008
Originally Posted by Narue View Post
>so i can't fix this?
It's hard to fix something that isn't broken. If you don't like the current result, change your formatting to better suit the display medium, or change the display medium to something better suited for your formatting.



I see. I was wondering, do you know if the prompt command box will delete initial output if the information being printed is too long or will it keep the entire history? It keeps chopping off and I am not sure if it’s something that I am doing wrong or if this is common?
Reply With Quote  
Join Date: Jan 2008
Posts: 1,490
Reputation: VernonDozier is a jewel in the rough VernonDozier is a jewel in the rough VernonDozier is a jewel in the rough VernonDozier is a jewel in the rough 
Rep Power: 6
Solved Threads: 187
VernonDozier VernonDozier is offline Offline
Nearly a Posting Virtuoso

Re: help formatting

  #10  
Jul 7th, 2008
Originally Posted by QuantNeeds View Post
I see. I was wondering, do you know if the prompt command box will delete initial output if the information being printed is too long or will it keep the entire history? It keeps chopping off and I am not sure if it’s something that I am doing wrong or if this is common?



In Windows XP, it'll chop off the output in the command window, and I imagine in other operating systems, the same is true. I just wrote a program to count from 0 to 100,000 and it only kept about the last 300 or so lines. The numbers before 99,700 were no longer visible in the console window after the program was done, even when I scrolled up to the top.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 11:59 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC