generating card box

closed account (iN8poG1T)
Hello im getting stuck to generate my card design. the output of my card is okey but when it comes to card no 9, theres is gap huge gap at number 9.

i am supposed to do it this way :


+---+ +---+ +---+ +---+ +---+ +---+ +---+ +---+ 
|  1|  |  2| |  3| |  4| |  5| |  6| |  7| |  8| 
|   | |   | |   | |   | |   | |   | |   | |   |
|   | |   | |   | |   | |   | |   | |   | |   |
+---+ +---+ +---+ +---+ +---+ +---+ +---+ +---+

+---+ +---+ +---+ +---+ +---+ +---+ +---+ +---+ 
|  9| | 10|  | 11|  | 12| | 13| | 14| | 15|  | 16| 
|   | |   | |   | |   | |   | |   | |   | |   |
|   | |   | |   | |   | |   | |   | |   | |   |
+---+ +---+ +---+ +---+ +---+ +---+ +---+ +---+


But instead i am getting this


+---+ +---+ +---+ +---+ +---+ +---+ +---+ +---+ 
|  1|  |  2| |  3| |  4| |  5| |  6| |  7| |  8| 
|   | |   | |   | |   | |   | |   | |   | |   |
|   | |   | |   | |   | |   | |   | |   | |   |
+---+ +---+ +---+ +---+ +---+ +---+ +---+ +---+

    +---+ +---+ +---+ +---+ +---+ +---+ +---+ +---+ 
     |  9| | 10|  | 11|  | 12| | 13| | 14| | 15|  | 16| 
     |   | |   | |   | |   | |   | |   | |   | |   |
     |   | |   | |   | |   | |   | |   | |   | |   |
     +---+ +---+ +---+ +---+ +---+ +---+ +---+ +---+ 




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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58

#include <cstdio>
#include <string>
using namespace std;

int main()
{
  string formatFaceDown[] = {
    "+---+",   // row = 0
    "|  %d|",  // row = 1
    "|   |",   // row = 2
    "|   |",   // row = 3
    "+---+"    // row = 4
  };

   string formatFaceDown2[] = {
    "+---+",   // row = 0
    "| %2d|",  // row = 1
    "|   |",   // row = 2
    "|   |",   // row = 3
    "+---+"    // row = 4
   };

  // r means row
  for (int r = 0; r < 5; ++r)
  {
    for (int c = 0; c < 8; ++c)
    {
      // Add space (if not the first card)
      if (c > 0)
        printf(" ");

      if (r == 1)
        printf(formatFaceDown[r].c_str(),
               c+1);
      else
        printf(formatFaceDown[r].c_str());
    }
    printf("\n");
  }
    for (int r = 0; r < 5; ++r)
  {
    for (int c = 8; c < 16; ++c)
    {
      // Add space (if not the first card)
      if (c > 0)
        printf(" ");

      if (r == 1)
        printf(formatFaceDown2[r].c_str(),
               c+1);
      else
        printf(formatFaceDown2[r].c_str());
    }
    printf("\n");
  }
}
Last edited on
closed account (iN8poG1T)
can anyone who is master in cpp tell me why mycard number 9 have ga? thank you
Last edited on
If you place your example in [output] tags, the forum will use fixed-width spaces, and preserve formatting. For example, entering
[output]+---+
|  %d|
|   |
|   |
+---+[/output]

Produces the following, with formatting preserved:
+---+
|  %d|
|   |
|   |
+---+
Last edited on
@keena

Try a small change on line 46. Your for loop is 8 thru 15 in line 43, yet your check if c > 0. It should be checking if c > 8, so it's not the first number, and does NOT add a space at the start of the line.
closed account (iN8poG1T)
@whitenite1

I change already but the number for all card at row 2 suddenly turn to 8 only. Not 9-16 as what i want. Is there anything i should change? :(
@keena

Could you display lines 41 to 57 as shown in the original post, but with the modification(s) you made?

I've run the modified source with no unexpected problems, so I'm thinking you changed more than just the one line of if (c > 0), which should now be if (c > 8)
Topic archived. No new replies allowed.