|
-
September 19th, 2004, 11:19 AM
#1
Need help for homework problem
I need to write a code for my homework result should should look like this:
********************
* empty spaces *
* empty spaces **
* empty spaces ***
* empty spaces ****
* *****
* ******
* *******
all the way down to this
********************
I wrote a "for loop" but with no help
my result comes too
********************
*
**
***
****
*****
******
*******
all the way down to this
********************
I wrote another "for loop" but with no help
my result comme to this
*********************
********************
*******************
all the way to this
*
*********************
Here is my source code
using System;
public class SquareWriteLine
{
public static void Main()
{
int column,height=20,width=20;
Console.WriteLine("-- Begin Shaded Square ({0} x {1})",20,20);
Console.Write("*"+"******************"+"*");
for (int row=0;row<height;++row)
{
for (column=0; column<row; column++)
Console.Write("*");
Console.WriteLine();
}
Console.WriteLine("*"+"******************"+"*");
Console.WriteLine("-- End Shaded Square ({0} x {1})",20,20);
}
}
Any help will be appreciated!!!
Bill
Last edited by bnovice; September 19th, 2004 at 11:27 AM.
-
September 19th, 2004, 01:16 PM
#2
Re: Need help for homework problem
I'm not sure I understand the output you desire, but I think you want something like:
Code:
*****
* *
* **
* ***
*****
If that's the case, then you weren't writing spaces to your 'rows'.
The following is probably what you need. Notice the use of constants.
Code:
using System;
public class SquareWriteLine
{
public static void Main()
{
const int INTERNAL_DIM=18;
Console.WriteLine("-- Begin Shaded Square ({0} x {0})",(INTERNAL_DIM+2));
Console.Write("*");
for (int a=0; a<INTERNAL_DIM; a++)
Console.Write("*");
Console.WriteLine("*");
for (int row=0;row<=INTERNAL_DIM;row++)
{
Console.Write("*");
for (int column=1; column<=(INTERNAL_DIM-row); column++)
Console.Write(" ");
for (int column=1; column<=row; column++)
Console.Write("*");
Console.WriteLine("*");
}
Console.WriteLine("-- End Shaded Square ({0} x {0})",(INTERNAL_DIM+2));
}
}
-
September 22nd, 2004, 06:01 AM
#3
Re: Need help for homework problem
Issa ...Thanks for your help. bnovice
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|