473,753 Members | 8,053 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Formatting output of an array

Hello,
I need help with formatting an output of an array.
I have a two dimensional array that looks something like this:

[1] x x x x
[2] y y y y
[3] b b b b

....and so on...I use [#] to just represent the row number whereas x, y, b
are some values in the array. I have no problem displaying the array on the
screen in the form above by using the following code:

for (down = 0; down < numStudents; down++)
{
cout << arrayStudents[down] <<"\t";

for (accross = 0; accross < numQuizzes; accross++)
{
cout << "\t" << arrayQuizzes[down][accross] <<"\t";

}
cout << endl;
}

But what I need is to display the array in the following form:

[1] [2] [3]
x y b
x y b
x y b

I tried modifying the code above so that the cout would display:
cout << "\t" << arrayQuizzes[accross][down] <<"\t";

But this only works if numStudents and numQuizzes are equal to each other.
If there are more students than there are quizzes then the array doesnt
display properly any more..

How else can I format the output so it looks like this:
[1] [2] [3]
x y b
x y b
x y b
but still works if the number of rows and columns are not equal.

Thanks

--
Steve - A+, I-Net+
Free PC Tech Support - http://www.webzila.com
DLL Files - http://www.dllplanet.com
Live Support - http://www.webzila.com/livesupport
Jul 22 '05 #1
1 4200
Steve wrote:
Hello,
I need help with formatting an output of an array.
I have a two dimensional array that looks something like this:

[1] x x x x
[2] y y y y
[3] b b b b

...and so on...I use [#] to just represent the row number whereas x, y, b
are some values in the array. I have no problem displaying the array on the
screen in the form above by using the following code:

for (down = 0; down < numStudents; down++)
{
cout << arrayStudents[down] <<"\t";

for (accross = 0; accross < numQuizzes; accross++)
{
cout << "\t" << arrayQuizzes[down][accross] <<"\t";

}
cout << endl;
}

But what I need is to display the array in the following form:

[1] [2] [3]
x y b
x y b
x y b

I tried modifying the code above so that the cout would display:
cout << "\t" << arrayQuizzes[accross][down] <<"\t";

But this only works if numStudents and numQuizzes are equal to each other.
If there are more students than there are quizzes then the array doesnt
display properly any more..

How else can I format the output so it looks like this:
[1] [2] [3]
x y b
x y b
x y b
but still works if the number of rows and columns are not equal.


How about swapping those 'for' statements of your nested loops instead
of swapping the indices?

V
Jul 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2979
by: shoo | last post by:
Any one know how to do this? thank Write a simple text-formatting program that produces neatly printed output from input text containing embedded command lines that determine how to format the output; all lines begin with a period are command lines. The task of the program is to collect words from input lines, fill output lines with those words, adjust the margins, and print the result. Your programs should handle the commands shown...
6
2742
by: shoo | last post by:
Any one know how to do this? thank Write a simple text-formatting program that produces neatly printed output from input text containing embedded command lines that determine how to format the output; all lines begin with a period are command lines. The task of the program is to collect words from input lines, fill output lines with those words, adjust the margins, and print the result. Your programs should handle the commands shown...
7
398
by: ilona | last post by:
Hi all, I store phone numbers in the database as 123447775665554(input mask is used for input, and some numbers have extensions), and I also know from db if the number is Canadian, US, or some other country. When I retrieve the phone numbers, I need to display them as (###) ###-#### x 99999 if it is a Canadian number or (###) ###-#### Ext. 99999 if it is US phone number. Potentially I'd have other countries added as well which might have...
1
1059
by: menotu3169 | last post by:
Alright, I'm just learning C++ and I'm trying to make a program. It uses a 10*10 array, calculates what all the values are and then outputs the values stored in the array on the screen. My teacher's out sick, and no one in my class has been able to help me. What I want to do, is take an array of double values, and output them on the screen in a nice looking format.
9
3209
by: sck10 | last post by:
Hello, I have a page with an ImageButton that is used to redirect to another page. When the page first opens, everything looks as expected. However, when I click on the image, the new page opens as expected. However, when I go back to the original page, all the font sizes are larger. Its as if by clicking on the ImageButton, my CSS formatting was discarded. When I look at the source for the following code, this is what I get:
6
1884
by: Rafael Olarte | last post by:
The goal of this project is to output the following information as follows: 34.5 38.6 4.1 42.4 3.8 close 46.8 4.4 big change. The values of the first colunm are obtain from a file called: tempInput.txt, and then the information is calculated, and it is output on a different file called tempOutput.txt. The tempInput.txt containg those numbers as follows:
1
3597
by: Wayne Deleersnyder | last post by:
Hi All, I was going to write and ask if someone could help me fix the formatting of my output for hash values, but I believe I got it right now. But, because I couldn't find any website or tutorial to help me with this issue I figured I'd make a post just in case someone else runs into the same issue. ....
4
3528
Sheepman
by: Sheepman | last post by:
My quest, to put 100 random numbers in ten rows of ten. Then output the same to the screen and a file. My screen output is working,yeah! Text file, not so much. The data is getting there but not formated. If word wrap is off it's a single row. If word wraps on, well ... it wraps. I've considered sizing the notebook window to wrap at the tenth character but I don't think the TA working on his Phd will buy it. Help please! My code for this portion...
0
1120
by: macbasic | last post by:
Hi, I am a learner who is automating some data from reports to ease my month end pressures. The code below is used to open a text file (a report from our ERP) and seperate the text into columns. Two of the arrays return dates. However, the dates get returned in both US and UK formats. Is there a way to apply formatting at this stage? Formatting later is too late as the date format is already corrupted. Workbooks.OpenText...
0
9072
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8896
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9451
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9333
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6869
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4771
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4942
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2872
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2284
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.