Table format?

So my prof wants us to to format our output in a table, i have everything but the actual output code.
Display the character for the ASCII codes 32 through 127, inclusive. Using a loop the output will result in a table format. Put the title ASCII Codes/Characters centered above the table.
The next line the table will be the column headings to identify the material in the table.

For each code value value in range given print both the code and the character for that code.
Make the printout readable with sets for 6 codes & the corresponding characters on each line printed
(that means 12 entries will be on each line). Use setw to space out each line in the table that is created.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
	char letter;

	cout << " I will display the characters for ASCII codes 32 through 127.\n";

	letter = 0;

	for(int count = 0; count <= 127; count++)
	{
        if (count % 12 ==0)
	    cout << endl;
		
        cout << letter << "  " << endl;
		letter++;
	} 
  //pause the program
  cin.sync();
  cin.get();
  return 0;
}

can anyone help me?
i once output all over the table, not allowed in that restaurant anymore either

hey could you use two nested for loops to print out an arrays, like a game board?
I think your professor is looking for something like this:

                                  ASCII Codes/Characters
============================================================================================
|| Code | Char || Code | Char || Code | Char || Code | Char || Code | Char || Code | Char ||
============================================================================================
||   32 |      ||   33 |   !  ||   34 |   "  ||   35 |   #  ||   36 |   $  ||   37 |   %  ||
||   38 |   &  ||   39 |   '  ||   40 |   (  ||   41 |   )  ||   42 |   *  ||   43 |   +  ||
||   44 |   ,  ||   45 |   -  ||   46 |   .  ||   47 |   /  ||   48 |   0  ||   49 |   1  ||
||   50 |   2  ||   51 |   3  ||   52 |   4  ||   53 |   5  ||   54 |   6  ||   55 |   7  ||
||   56 |   8  ||   57 |   9  ||   58 |   :  ||   59 |   ;  ||   60 |   <  ||   61 |   =  ||
||   62 |   >  ||   63 |   ?  ||   64 |   @  ||   65 |   A  ||   66 |   B  ||   67 |   C  ||
||   68 |   D  ||   69 |   E  ||   70 |   F  ||   71 |   G  ||   72 |   H  ||   73 |   I  ||
||   74 |   J  ||   75 |   K  ||   76 |   L  ||   77 |   M  ||   78 |   N  ||   79 |   O  ||
||   80 |   P  ||   81 |   Q  ||   82 |   R  ||   83 |   S  ||   84 |   T  ||   85 |   U  ||
||   86 |   V  ||   87 |   W  ||   88 |   X  ||   89 |   Y  ||   90 |   Z  ||   91 |   [  ||
||   92 |   \  ||   93 |   ]  ||   94 |   ^  ||   95 |   _  ||   96 |   `  ||   97 |   a  ||
||   98 |   b  ||   99 |   c  ||  100 |   d  ||  101 |   e  ||  102 |   f  ||  103 |   g  ||
||  104 |   h  ||  105 |   i  ||  106 |   j  ||  107 |   k  ||  108 |   l  ||  109 |   m  ||
||  110 |   n  ||  111 |   o  ||  112 |   p  ||  113 |   q  ||  114 |   r  ||  115 |   s  ||
||  116 |   t  ||  117 |   u  ||  118 |   v  ||  119 |   w  ||  120 |   x  ||  121 |   y  ||
||  122 |   z  ||  123 |   {  ||  124 |   |  ||  125 |   }  ||  126 |   ~  ||  127 |     ||
============================================================================================
that is what I am trying for, but I have to write the code to output that, I can't just type the chart into my output
Well I don't think I'm supposed to just give you the code... you're supposed to figure it out yourself.

Here are 3 problems (there are more) with the code you posted:

1. Your initial value for "letter" is 0, when it should be 32.
2. Your loop iterates a total of 128 times (0 to 127) when it should be 96 times.
3. Each line of the table is supposed to be 6 sets of 2, for 12 entries, not 12 sets of 1.
I currently have it outputting the numbers and symbols, but I can't seem to get the spacing right, and the top row keeps splitting in half and starting on the next row. It doesn't hurt to just point out something in a segment of code, I've helped people before. I fixed part of it.
1
2
3
4
5
6
7
8
9
10
letter = 32;

for(int count = 32; count <= 127; count++)
{
 if (count % 6 ==0)
   cout << endl;
		
   cout << letter << "| " << count << " |";
   count+1; letter++;
} 
You should either change it to this:

1
2
3
for(int count = 32; count <= 127; count++)
{
 if ((count - 32) % 6 ==0)


or this:

1
2
3
for(int count = 0; count < 96; count++)
{
 if (count % 6 ==0)


That will fix your top row.
Neither of those fixed it actually, the first one made it worse and the second displayed a different set of symbols.
This is the loop I used to generate the chart (basically your whole assignment):

1
2
3
4
5
6
    for(int letter = 32; letter < 128; letter++)
    {
        if ((letter - 32) % 6 == 0)
            fout << "\n||";
        fout << setw(5) << letter << " | " << setw(3) << (char)letter << "  ||";
    }


The fout is because I'm outputting to a file instead of the console so I could copy/paste the table to my post, and because my console window only has a width of 80 characters per line.
Last edited on
i already figured that out, i tweaked it a little, I use this more as a sounding board to bounce things off of, all I can't seem to do now, is center the title and add column headings
Topic archived. No new replies allowed.