lundi 23 mai 2016

draw border using for loop

I'm trying to make a simple border using for loop. I don't get a proper result. Specifically, my right border is not shown. Please help.

const int width = 20;
const int height = 20;

void Drow() 
{
    system("cls");                      // clear the screan
    for (int i = 0; i < width; ++i) 
    {
        cout << "*";                    // upper border
    }       

    for (int i = 0; i < height-2; i++) 
    {
        for (int j = 0; j < width; j++) 
        {
            if (j == 0 || j == width - 1)
            {
                cout << "*";            // left and right borders
            }
        }
        cout << endl;
    }

    for (int i = 0; i < width; i++)     // lower border
        cout << "*";
}

Aucun commentaire:

Enregistrer un commentaire