C
C++ Newbie
The following snippet of code shows how a rectangle of user-defined
height & width may be printed on screen in C++ (the C++ NG appears to
be down to Google Groups).
Referring to my FOR loops, is there any way in which the columns may
be iterated in the outer loop rather than the rows, and still yield a
workable result?
Ask if you want the full source code, I didn't think it was necessary
as this deals more with concepts.
case ('r'): cout << "Rectangle selected\n";
cout << "Enter width\n";
cin >> width;
cout << "Enter height\n";
cin >> height;
columns = rows = 0;
for (rows = 0; rows < height; rows++)
{
cout << '\n';
for (columns = 0; columns < width; columns++)
{
if (rows==0)
{cout << '*';}
if (rows>0 && rows < height-1)
{if (columns == 0 || columns ==
width-1)
{cout << '*';}
if (columns > 0 && columns < width-1)
{cout<<' ';}}
if (rows==height-1)
{cout << '*';}
}
}
break;
height & width may be printed on screen in C++ (the C++ NG appears to
be down to Google Groups).
Referring to my FOR loops, is there any way in which the columns may
be iterated in the outer loop rather than the rows, and still yield a
workable result?
Ask if you want the full source code, I didn't think it was necessary
as this deals more with concepts.
case ('r'): cout << "Rectangle selected\n";
cout << "Enter width\n";
cin >> width;
cout << "Enter height\n";
cin >> height;
columns = rows = 0;
for (rows = 0; rows < height; rows++)
{
cout << '\n';
for (columns = 0; columns < width; columns++)
{
if (rows==0)
{cout << '*';}
if (rows>0 && rows < height-1)
{if (columns == 0 || columns ==
width-1)
{cout << '*';}
if (columns > 0 && columns < width-1)
{cout<<' ';}}
if (rows==height-1)
{cout << '*';}
}
}
break;