Draw A Rectangle With Asterisks

前端 未结 4 1491
眼角桃花
眼角桃花 2021-01-29 13:23

I am trying to write a C++ Program to display a rectangle drawn in asterisks. I have the program running properly except for the fact that only one side of the heights of my rec

4条回答
  •  半阙折子戏
    2021-01-29 13:43

    Well, you don't see the second vertical line, because you don't draw it in your line loop.

    void DrawRect(int w, int h, char c)
    {
        cout << string(w, c) << '\n';
        for (int y = 1; y < h - 1; ++y)
            cout << c << string(w - 2, ' ') << c << '\n';
        cout << string(w, c) << '\n';
    }
    

提交回复
热议问题