Click to See Complete Forum and Search --> : Need help for homework problem


bnovice
September 19th, 2004, 11:19 AM
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

Issa
September 19th, 2004, 01:16 PM
I'm not sure I understand the output you desire, but I think you want something like:



*****
* *
* **
* ***
*****


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.

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));
}
}

bnovice
September 22nd, 2004, 06:01 AM
Issa ...Thanks for your help. bnovice