| Subject: | Printing simple shapes on screen |
|---|---|
| From: | "C++ Newbie" |
| Date: | Wed, 2 Apr 2008 02:40:39 -0700 PDT |
| Newsgroups: | comp.lang.c |
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;
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| ||
| Previous by Date: | Re: Makes it sense to get a copy of the ANSI standard documents?, Bartc |
|---|---|
| Next by Date: | Re: Undefined behaviour in expressions, Nick Keighley |
| Previous by Thread: | Strange sintax, InuY4sha |
| Next by Thread: | Re: Printing simple shapes on screen, Richard Heathfield |
| Indexes: | [Date] [Thread] [Top] [All Lists] |