ASCII art not printing

I'm having trouble figuring out why the console is not printing out the ASCII art.
Side note, there might be a few other mathematical issues as well as the fact that I'm purposely not using the <iomanip> library, but I can work those out later.

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
  void House::Draw() const {
    int leg = base + 2;
    for (int i=1; i>=leg; i++) {
        if (i = 1) {
            for (int j=1; j>=leg/2; j++) {
                cout << "  ";
            }
            cout << border << " " << endl;
        }
        if (i = 2) {
            for (int k=1; k>=(leg/2)-1; k++) {
                cout << "  ";
            }
            cout << border << " " << border << " " << endl;
        }
        if (i >= 3 && i < leg) {
            for (int l=leg-2; l==1; l--) {
                cout << "  ";
            }
            cout << border;
            for (int j=1; j>=leg-2; j++) {
                cout << fill << " ";
            }
            cout << border << endl;
        }
        if (i = leg) {
            cout << border << " " << border << " ";
            for (int k=1; k>=leg-4; k++) {
                cout << fill << " ";
            }
            cout << border << border << endl;
        }
    }
}
You don't show the definition of border.

If you're trying to use the extended ASCII line drawing characters, check the following thread:
http://www.cplusplus.com/forum/beginner/248878/#msg1096546

@AbstractionAnon

Could you explain what you mean? If it helps, the function I'm writing is part of a larger class.
What is the definition of border? It's not shown in your code snippet.

As the article linked above states, cout is limited to signed characters (0-127).
Extended ASCII (128-255) has line drawing characters.
See 179-218 here:
https://stackoverflow.com/questions/13826781/java-extended-ascii-table-usage
If you try cout extended ASCII, the result is undefined behavior.
Use wide characters instead.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
enum class EXT_ASCII : wchar_t
{
    VERT_BAR = 179,
    RIGHT_T = 180,
    UPPER_R = 191,
    LOWER_L = 192,
    BOTTOM_T = 193,
    TOP_T = 194,
    LEFT_T = 195,
    HORIZ_BAR = 196,
    CROSS = 197,
    LOWER_R = 217,
    UPPER_L = 218
};
    wcout << EXT_ASCII::VERT_BAR;



I think I understand what you mean. border and fill are already defined as 'X' and '*' by default when they are called.

1
2
3
4
5
6
7
8
9
// ... 
    void Draw() const;

    void Summary() const;
private:
    int base = 3;
    char border = 'X';
    char fill = '*';
};


The issue is that the program isn't drawing anything to the terminal when I call the Draw() function. I know all my syntax is correct, but something about my loops just int working, and I cant find it.
Last edited on
Okay, so we're not talking about extended ASCII.

One problem is immediately apparent. Lines 4,10,26 you're using the wrong operator.
= is the assignment operator. You want the equality operator ==.

Second problem: Lines 3,5,6,11 Your termination conditions are wrong. Consequently, none of your cout statements operate.

Use a debugger and step through your code.

Last edited on
I've spent some time to rework the loops, and now I've arrived at different issue.
I'm trying to fill the "roof" of the house I'm trying to print, but I can only get the program to draw 1 filler character or a fixed amount of them and its breaking the pattern. Any ideas?

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
void House::Draw() const {
    // Roof section
    for(int i = 1; i <= base+1; i++) {
        for(int space = base+2; space > i; space--) {
            cout << " ";
        }
        int j = 0;
        while (j != (2*i-1)) {
            if (j == 0 || j == 2*i-2) {
                cout << border << " ";
            }
            else if (j == i) {
                cout << fill << " ";
            }
            j++;
        }
        cout<<endl;
    }
    cout << border << " " << border << " ";
    for (int k = 1; k <= base-2; k++) {
        cout << fill << " ";
    }
    cout << border << " " << border << " " << endl;

    // Body section
    for (int i = 1; i <= base-2; i++) {
        cout << "  ";
        cout << border << " ";
        for (int j = 0; j < base-2; j++) {
            cout << fill << " ";
        }
        cout << border;
        cout << endl;
    }
    cout << "  ";
    for (int k = 0; k <= base-1; k++) {
        cout << border << " ";
    }
    cout << endl;
}


The problem area is lines 12 and 13, I think.
As has been mentioned above, use the debugger to trace through the program to determine the issue.
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
59
60
61
62
#include <iostream>
using namespace std;

class House
{
   int base;
   char border, fill;
public:
   House( int ba, char bo, char fi ) : base( ba ), border( bo ), fill( fi ) {}
   void Draw() const;
};


// ********** YOUR CODE *************
void House::Draw() const {
    // Roof section
    for(int i = 1; i <= base+1; i++) {
        for(int space = base+2; space > i; space--) {
            cout << " ";
        }
        int j = 0;
        while (j != (2*i-1)) {
            if (j == 0 || j == 2*i-2) {
                cout << border;             // <==== no extra ' '
            }
            else {                          // <==== just "else"
                cout << fill;               // <==== no extra ' '
            }
            j++;
        }
        cout<<endl;
    }
    cout << border << " " << border << " ";
    for (int k = 1; k <= base-2; k++) {
        cout << fill << " ";
    }
    cout << border << " " << border << " " << endl;

    // Body section
    for (int i = 1; i <= base-2; i++) {
        cout << "  ";
        cout << border << " ";
        for (int j = 0; j < base-2; j++) {
            cout << fill << " ";
        }
        cout << border;
        cout << endl;
    }
    cout << "  ";
    for (int k = 0; k <= base-1; k++) {
        cout << border << " ";
    }
    cout << endl;
}

// ********** END OF YOUR CODE *************

int main()
{
   House h( 20, '#', '.' );
   h.Draw();
}



Here's your happy house:

                     #
                    #.#
                   #...#
                  #.....#
                 #.......#
                #.........#
               #...........#
              #.............#
             #...............#
            #.................#
           #...................#
          #.....................#
         #.......................#
        #.........................#
       #...........................#
      #.............................#
     #...............................#
    #.................................#
   #...................................#
  #.....................................#
 #.......................................#
# # . . . . . . . . . . . . . . . . . . # # 
  # . . . . . . . . . . . . . . . . . . #
  # . . . . . . . . . . . . . . . . . . #
  # . . . . . . . . . . . . . . . . . . #
  # . . . . . . . . . . . . . . . . . . #
  # . . . . . . . . . . . . . . . . . . #
  # . . . . . . . . . . . . . . . . . . #
  # . . . . . . . . . . . . . . . . . . #
  # . . . . . . . . . . . . . . . . . . #
  # . . . . . . . . . . . . . . . . . . #
  # . . . . . . . . . . . . . . . . . . #
  # . . . . . . . . . . . . . . . . . . #
  # . . . . . . . . . . . . . . . . . . #
  # . . . . . . . . . . . . . . . . . . #
  # . . . . . . . . . . . . . . . . . . #
  # . . . . . . . . . . . . . . . . . . #
  # . . . . . . . . . . . . . . . . . . #
  # . . . . . . . . . . . . . . . . . . #
  # . . . . . . . . . . . . . . . . . . #
  # # # # # # # # # # # # # # # # # # # # 
Here's your happy house....

There's something fishy goin' on here:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <cmath>

double fish(int x)
{
   double xx = (x - 16) * (x - 16);

   return abs(x < 16 ? sqrt(64.0 - xx / 4.0) : 8 - 0.01 * xx);
}

int main()
{
   for (int j = 8; j >= -8; j--)
   {
      for (int i = 0; i < 56; i++)
      {
         std::cout << (abs(j) <= fish(i) ? '*' : ' ');
      }
      std::cout << '\n';
   }
}

                *
         ******************                            *
      *************************                       **
    ******************************                   ***
   **********************************              *****
  *************************************           ******
 ****************************************       ********
 ******************************************   **********
********************************************************
 ******************************************   **********
 ****************************************       ********
  *************************************           ******
   **********************************              *****
    ******************************                   ***
      *************************                       **
         ******************                            *
                *
Registered users can post here. Sign in or register to post.