CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2010
    Posts
    46

    Outputing a square.

    so my only question is how to make my output screen like this:

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

    instead of this:
    *
    *
    *
    *

    Heres the code: I jus basically need the answer, i can figure it out from the code you use. THX

    Also this is a function im calling, not the entire program.

    void display()
    {
    char ch;
    int i, j, side;
    cout<<"Enter character and side"<<endl;
    cin>>ch>>side;
    cout<<endl;

    for(int i=0; i<side/2; i++)
    {
    for(int j=0; j<side/2; j++)
    {
    cout<<ch<<endl;
    }
    }
    }

  2. #2
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: Outputing a square.

    Quote Originally Posted by Jinzui View Post
    Code:
    cout<<ch<<endl;
    What do you think this "<<endl;" does?
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  3. #3
    Join Date
    Apr 2009
    Posts
    27

    Re: Outputing a square.

    void display()
    {
    char ch;
    int i, j, side;
    cout<<"Enter character and side"<<endl;
    cin>>ch>>side;
    cout<<endl;

    for(int i=0; i<side/2; i++)
    {
    for(int j=0; j<side/2; j++)
    {
    cout<<ch;
    }
    cout<<endl;
    }
    }

    I don't know why you are doing side/2. I think it should just simply be side.
    Last edited by sgsawant; March 23rd, 2010 at 10:43 PM. Reason: I clicked submit accidentally.

  4. #4
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Outputing a square.

    You could try this helper class that I wrote: http://mariusbancila.ro/blog/2008/11...ole-functions/.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

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