Article View: alt.comp.lang.learn.c-c++
Article #174Re: Basic Loop problem.
From: Cameron Foster
Date: Mon, 19 Oct 1998 00:00
Date: Mon, 19 Oct 1998 00:00
47 lines
2488 bytes
2488 bytes
On Sat, 17 Oct 1998 15:39:39 -0700, Wasilefsky <berard@uswest.net>
wrote:
>Hey, I'm having this problem for a school project. I just started
>learning for loops & stuff so I really don't know this stuff.
>Basically, what the program has to do is something like this:
>
>
> Enter in the length of the square. Enter -1 to quit [5]
> +---+
> | |
> | |
> | |
> +---+
>
>Notice how when the user enters 5, the distance from the + to the other
>plus, both horizontally & vertically is 5. This is what I can't get
>done. Any help will be greatly appreciated. From what I understand
>this is all loop stuff, which we just barely learned.
>
Without seeing the code you wrote to attempt to solve this problem, it
is a little difficult to be very helpful. Presumably, you need to
request input from the user which will give you the dimensions of the
square to be generated. Say the user inputs "5", or "five", or "Five".
You then have a number which can be used as a terminating condition
for a loop which prints (in this case) 5 lines. You also have a number
which can be used as a terminating condition for another loop which
determines how many characters to print on each line. What you need to
do is figure out an algorithm which can convert the information you
have available to produce the results you want. (Hint: nested loops):
for(i = 0; i < n; ++i) {
for(j = 0; j < n; ++j)) {
/* some more code here possibly involving the */
/* current values of i and j /*
}
}
After you work out the code, if there are still problems, then follow
Mr. Klein's advice and post the offending code, and someone will
likely point you in the right direction.
--
Cameron Foster
cdfoster@ix.netcom.com
http://www2.netcom.com/~cdfoster/
Technical Details
Message-ID:
<362dbdaf.9134540@nntp.ix.netcom.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<36291CAA.CC3A57E9@uswest.net>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10d4ba,10524d27e9fda721 X-Google-Attributes: gid10d4ba,public X-Google-Thread: 114592,10524d27e9fda721 X-Google-Attributes: gid114592,public From: cdfoster@ix.netcom.com (Cameron Foster) Subject: Re: Basic Loop problem. Date: 1998/10/19 Message-ID: <362dbdaf.9134540@nntp.ix.netcom.com> X-Deja-AN: 402691189 Content-Transfer-Encoding: 7bit References: <36291CAA.CC3A57E9@uswest.net> Content-Type: text/plain; charset=us-ascii Organization: ICGNetcom X-NETCOM-Date: Sun Oct 18 11:46:25 PM CDT 1998 Mime-Version: 1.0 Reply-To: cdfoster@ix.netcom.com Newsgroups: alt.comp.lang.learn.c-c++,att.lang.c++