CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2004
    Posts
    2

    Unhappy 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.

  2. #2
    Join Date
    Sep 2004
    Location
    Toronto, Canada
    Posts
    103

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

  3. #3
    Join Date
    Sep 2004
    Posts
    2

    Smile 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
  •  





Click Here to Expand Forum to Full Width

Featured