Printing out in columns using a for loop

Hello everyone,

I've been spending hours trying to figure this out, but haven't found any solution to my problem yet, so I thought it might be worth asking here.

I have an assignment where I am to print out numbers 32 - 255 and their corresponding ASCII characters.
I have done that, but I am suppose to print it out in columns and I'm only able to print it out in rows.

The layout is suppose to look something like this:
32 64 @ 96 `
33 ! 65 A 97 a
34 " 66 B 98 b
35 # 67 C 99 c
36 $ 68 D 100 d
37 % 69 E 101 e
38 & 70 F 102 f
39 ' 71 G 103 g
40 ( 72 H 104 h
41 ) 73 I 105 i
42 * 74 J 106 j

Any help would be much appreciated!

My code is below.

1
2
3
4
5
 int main()
{
		for (int a = 32; a < 256; a++)
			cout << a << " - " << char(a) << " "; 
	return 0;
1
2
3
4
5
6
7
8
9
10
11
int counter=0;
for (int a = 20; a <= 0xFF; ++a,++counter)
	{ 
          if(counter==4)
             { 
                std::cout<<'\n';
                counter=0;
             }
          std::cout << a << " - " << char(a) << " ";
        }
Thank you for the answer, but I need it to print out in the same order as the layout in the original post. What I mean is the numbers have to count up vertically (as in a column) and not horizontally (rows).

This picture explains it pretty well:

https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcQno8QXyLJi748455mEJWs-s2MkUxhkAV1XsgHNiM7Lus9Wxwa-GA

So I guess what I'm looking for is how to print it out in a column-major order
Last edited on
Previous thread: Print ascii table
http://www.cplusplus.com/forum/beginner/202829/
Last edited on
Thank you very much! That was exactly what I needed.

Sorry for opening a new thread for this. I tried searching, but obviously didn't do a good enough job.

Again, thank you, both of you.
You're welcome. No need to apologise, I only found it because I knew it was there, and the approximate date.
Topic archived. No new replies allowed.