Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C > Printing simple...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 4 Topic 25284 of 27671
Post > Topic >>

Printing simple shapes on screen

by "C++ Newbie" <newbie.cpp@[EMAIL PROTECTED] > Apr 2, 2008 at 02:40 AM

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;
 




 4 Posts in Topic:
Printing simple shapes on screen
"C++ Newbie" &l  2008-04-02 02:40:39 
Re: Printing simple shapes on screen
Richard Heathfield <rj  2008-04-02 10:07:14 
Re: Printing simple shapes on screen
rlb@[EMAIL PROTECTED] (R  2008-04-02 10:17:48 
Re: Printing simple shapes on screen
Antoninus Twink <nospa  2008-04-03 00:23:08 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Oct 11 8:44:29 CDT 2008.