473,327 Members | 2,069 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

aligning numbers in C++ (layout problem)

11
Hi guys :)

ok so i have something like this

Expand|Select|Wrap|Line Numbers
  1. for(i=0;<10;i+)
  2. {
  3.      cout<<"\n\n"<<setw(15)<<somenumber[i]<<setw(25)<<someinteger[i];
  4. }
  5.  
The problem is that because the numbers from somenumber[] are different lengths, the numbers from someinteger[] dont come out aligned nicely under eachother :( how do i fix this? Is there a command that could align them to the right? Thx guys! :)
Aug 30 '07 #1
2 3770
kreagan
153 100+
Hi guys :)

ok so i have something like this

Expand|Select|Wrap|Line Numbers
  1. for(i=0;<10;i+)
  2. {
  3.      cout<<"\n\n"<<setw(15)<<somenumber[i]<<setw(25)<<someinteger[i];
  4. }
  5.  
The problem is that because the numbers from somenumber[] are different lengths, the numbers from someinteger[] dont come out aligned nicely under eachother :( how do i fix this? Is there a command that could align them to the right? Thx guys! :)
maybe you can insert a if statement that states (assuming that numbers ranges from 1 - 1000 for this example)

if ( somenumber[i] < 100) { add 2 spaces }
else if ( some number[i] < 1000) { add 1 spaces }
Aug 30 '07 #2
RRick
463 Expert 256MB
You shouldn't have to worry about the size of the int using setw. It's suppose to take care of that automatically.

With setw you should have gotten numbers printed with some constant spacing. I believe the default justification is right-justified. Try left instead.
Expand|Select|Wrap|Line Numbers
  1. cout << left << setw( .....
Aug 30 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: mkarja | last post by:
Hi, I have a GUI which has textboxes in it. Those boxes can contain either numbers or text. The problem is that the numbers allways goes to the other side of the box than text. They should both...
3
by: Hal Vaughan | last post by:
I have a JComboBox with a list of numbers, from 1 digit to 5 digits. Numbers with more than 3 digits have a comma in them. I've been aligning them with leading spaces. Is there any simple and...
1
by: Graham Cross | last post by:
Dear All Is there an HTML way of aligning the images on this page http://www.ageconcernleics.com/review03/chairs03.html so that they appear evenly spaced relative to the text column on the...
1
by: Linux Boy via .NET 247 | last post by:
(Type your message here) Hi everyone, I would like to ask a question about aligning text within one label. I have an application that everytime the user click on Enter Record button, they will...
5
by: Raj | last post by:
Hi, I have a ASP.NET project which is working fine and I need to align controls in a .aspx page. The webform( .aspx page) has variety of controls (labels, textboxes, radio buttons etc) and when...
3
by: Mark Wiewel | last post by:
hi all, i am a newbie in ASP.NET and i couldn't find the solution to this one: i have a form with three datagrids on it. i would like to align them vertically with a space between each grid of...
4
by: matticus00 | last post by:
Hello. I'm putting together a css layout, and I have a large header <div>. Within that <div>, I would like to have a smaller <div> to put some navigation in, and have it be aligned to the TOP-RIGHT...
2
by: agbee1 | last post by:
Hello: I've finally made the effort to ween myself from overly using tables and use CSS for my positioning. However, I am having a problem with my navigational menu properly aligning in Firefox,...
8
by: neovantage | last post by:
Hey all, I have alignment problem in layout. I am using slideshow technology. It shows images in background and text over the background image once we take mouse over the link buttons. Now what my...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.