Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Use the character code representations and the fact that 'b' == 'a' + 1 (and so forth).</p> <p>If you have a zero-based index I, and you want to convert that to letters, it really is as easy as printing 'a' + I. If you want it in caps, print 'A' + I.</p> <p>Also note that you can really simplify those loops. There's no reason to have three loops nested. You need a single for loop for the first row (generating the numeric column headers), and then a doubly-nested for-loop for the remaining rows. Something like the following (completely untested) code:</p> <pre><code>// print header std::cout &lt;&lt; ' '; for (int i = 0; i != x; ++i) std::cout &lt;&lt; ' ' &lt;&lt; i; std::cout &lt;&lt; '\n'; // print body for (int j = 0; j != y; ++j) { // column leader std::cout &lt;&lt; char('a' + j); // column body for (int i = 0; i != x; ++i) std::cout &lt;&lt; " _"; std::cout &lt;&lt; "\n"; } </code></pre> <p>Following up on your desire to have data in cells, you need to allocate space for them. if you have X columns by Y rows, you need X*Y cells. You can index these by using X*j+i, where i,j is the column,row you want to access. Something like:</p> <pre><code>std::vector&lt;int&gt; cells(x * y); // inside the loop, in place of printing " _", use: std::cout &lt;&lt; ' ' &lt;&lt; cells(x * j + i); </code></pre> <p>If you want to keep the underscore for "empty" values, you need to pick some integer to represent a nil value (zero, negative, INT_MAX, whatever) and fill the vector with that. Then put in an if condition to print the underscore if the cell value is the nil value, and print the cell value directly otherwise.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload