🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.comp.lang.learn.c-c++
Article #173

Continuation....Basic Loop Problem.

#173
From: Wasilefsky
Date: Sun, 18 Oct 1998 00:00
126 lines
5204 bytes
Ok, thanks to everyones help and a lot of improvision, I have been doing
very good on my basic loop problem.  Except right now I can't get it to
do 2 things.  One, I need to get the average size (depending on how many
times someone enters the size of the box) of the boxes entered, as well
as my output still is'nt exactly what it needs to be.  The spacing/ -'s
are right going across, but not the |'s going down.  Here's what I got:

#include <iostream.h>
#include <iomanip.h>
void main (void)

{

        int length = 0, average = 1, count, totaltest = 0, totallength =
0, side, box = 0, space;

        char answer;
        const int START = 1;
        while (box == 0)

        {

                cout << "Enter in the length of the square.  Enter -1 to
quit\t";
                cin >> length;

                cout << setiosflags(ios::fixed)
                         << setiosflags(ios::right);

                if (length < 1 && length != -1 || length > 24)

                {
                        cout << "Invalid data.  The lenght must be
[1-24].\n"
                                 << "Enter in the length of the square.
Enter -1 to quit\t";
                        cin >> length;
                }

                else if (length == -1)
                {
                        count = 0;
                        while (count == 0)
                        {
                                cout << "Would you like to repeat the
program?\t";
                                cin >> answer;

                                if (answer == 'y' || answer == 'Y')
                                {
                                        box = 0;
                                        count = 1;
                                        length = 0;
                                        break;
                                }
                                else if ( answer == 'n' || answer ==
'N')
                                {
                                        box = 1;
                                        count = 1;
                                        break;
                                }
                                else
                                {
                                        cout << "You have entered an
invalid choice. Please try again." << endl;
                                        count = 0;
                                        length = 0;
                                }
                        }
                }

                if ( answer == 'n' || answer == 'N')
                        break;

                space = length - 1;

                switch (length)
                {
                        case 0:
                                break;

                        case 1:
                                totaltest++;
                                totallength = totallength + 1;
                                cout << "+\n";
                                box = 0;
                                break;

                        case 2:
                                totaltest++;
                                totallength = totallength + 2;
                                cout << "++" << endl <<"++" << endl;
                                box = 0;
                                break;

                        default:
                                totaltest++;
                                totallength = totallength + length;
                                side = length-2;  // adjustment for
larger boxes
                                cout << "+";
                                count = 0;

                                for (count = 0; count < side; count++)
                                        cout << "-";

                                cout << "+\n";
                                count = 0;
                                for (count = 0; count < side; count++)
                                        cout << "|" << setw(space) <<
"|" << endl;

                                cout << "+";
                                count = 0;
                                for (count = 0; count < side; count++)
                                        cout << "-";

                                cout << "+\n";
                                box = 0;

                }

        }

}
Technical Details
Message-ID: <362A7138.EE71830A@uswest.net>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10d4ba,374ef867f4da62c7,start
X-Google-Attributes: gid10d4ba,public
X-Google-Thread: 114592,374ef867f4da62c7,start
X-Google-Attributes: gid114592,public
X-Google-Thread: 109fba,374ef867f4da62c7,start
X-Google-Attributes: gid109fba,public
From: Wasilefsky <berard@uswest.net>
Subject: Continuation....Basic Loop Problem.
Date: 1998/10/18
Message-ID: <362A7138.EE71830A@uswest.net>
X-Deja-AN: 402611883
X-Report: Report abuse to abuse@uswest.net.
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset=us-ascii
X-Trace: 18 Oct 1998 17:52:21 +0500, 207.225.170.105
Organization: America Online
MIME-Version: 1.0
Newsgroups: alt.comp.lang.learn.c-c++,att.lang.c++,comp.lang.c++