How to Display a square

This is a discussion on How to Display a square within the C++ Programming forums, part of the General Programming Boards category; For days i been trying to display an square with a length and the symbol that is been entered by ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    9

    Question How to Display a square

    For days i been trying to display an square with a length and the symbol that is been entered by the user. can you please help me?

    PS: this should be the output

    *****
    *``` *
    *``` *
    * ```*
    *<----*---space in the middle
    *****
    for WINDOWS

    Thank you all for your feed back

    Last edited by moenia; 04-29-2002 at 01:19 PM.

  2. #2
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    What kind of app? Console or Win32?

    Console cout/printf the character for your box outline and use
    gotoxy (or (depending on your compiler) the alternative listed in
    the FAQ).

    Win32 just use MoveToEx and LineTo to go from your 4 corners.

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    9

    Arrow

    .cpp.cpp .cpp

  4. #4
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    ??

  5. #5
    Fingerstyle Guitarist taylorguitarman's Avatar
    Join Date
    Aug 2001
    Posts
    564
    Something like this?
    Code:
    output:
    
    Enter square size: 4
    Enter symbol to use: -
    ----
    ----
    ----
    ----
    Code:
    #include <iostream>
    using namespace std;
    
    int main( int argc, char **argv ) {
    
      int   size;
      int   row;
      int   column;
      char  symbol;
    
      cout << "Enter square size: ";
      cin >> size;
    
      cout << "Enter symbol to use: ";
      cin >> symbol;
    
      for( row = 0; row < size; row++ ) {
        
        for( column = 0; column < size; column++ ) {
          
          cout << symbol;
        }
    
        cout << endl;
      }
    
      return 0;
    }
    Next time post what you have first or be more specific.
    If a tree falls in the forest, and no one is around to see it, do the other trees make fun of it?

  6. #6
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    Originally posted by moenia
    .cpp.cpp .cpp
    Read my reply again. What kind of app (console or win32), NOT what language you're writing in.

  7. #7
    Registered User
    Join Date
    Dec 2001
    Posts
    206
    as in : are you making a program for DOS or WINDOWS?

  8. #8
    Intranasal Heroin User Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,035
    ack! maybe he doesn't know what kind of output it is? i dont like it when you people tell beginners complicated jargons. Let's try somthing easier, like what compiler are you using? we can tell from there.

  9. #9
    Registered User
    Join Date
    Dec 2001
    Posts
    28
    Mine is a bit different from yours, sorry, but I already had it done. You should be able to figure it out from this code though.

    Code:
    #include <iostream.h>
    
    void draw_square(int length, char character)
    {
    	cout << "+ ";
    	
    	for (int horizontal=0; horizontal < (length-2); horizontal++)
    	{
    		cout<<"- ";
    	}
    
    	cout << "+" << endl;
    
    	for (int vertical=0; vertical<(length-2); vertical++)
    	{
    		cout << "| ";
    
    		for (int whitespace=0; whitespace < (length + length - 5); whitespace++)
    		{
    			cout << character;
    		}
    
    		cout << " |" << endl;
    	}
    
    	cout << "+ ";
    	
    	for (horizontal=0; horizontal < (length-2); horizontal++)
    	{
    		cout<<"- ";
    	}
    
    	cout << "+" << endl;
    }
    
    int main()
    {
    int length_of_square=0;
    char userchar=0;
    		
    	cout << "Enter the length of the square" << endl;
    	cin >> length_of_square;
    	cout<<"What character should we use?"<<endl;
    	cin>>userchar;
    
    	if (length_of_square == 0)
    		return 0;
    
    	if (length_of_square < 0)
    	{
    		cout << "Incorrect length.";
    		return 0;
    	}
    
    	draw_square(length_of_square, userchar);
    
    return 0;
    }

  10. #10
    Fingerstyle Guitarist taylorguitarman's Avatar
    Join Date
    Aug 2001
    Posts
    564
    You're lazy. Next time you're going to have to show some effort

    Code:
    #include <iostream>
    using namespace std;
    
    int main( int argc, char **argv ) {
    
      int   size;
      int   row;
      int   column;
      char  symbol;
    
      cout << "Enter square size: ";
      cin >> size;
    
      cout << "Enter symbol to use: ";
      cin >> symbol;
    
      for( row = 0; row < size; row++ ) {
        
        cout << symbol;
    
        for( column = 0; column < size - 2; column++ ) {
        
          if( row == 0 || row == size - 1 ) {
    
            cout << symbol;
          }
          else {
            
            cout << ' ';
          }
        }
    
        cout << symbol;
    
        cout << endl;
      }
    
      return 0;
    }
    If a tree falls in the forest, and no one is around to see it, do the other trees make fun of it?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Tic Tac Toe Comp Move help
    By swgh in forum C++ Programming
    Replies: 5
    Last Post: 09-24-2008, 11:05 AM
  2. Loop seg error
    By Zishaan in forum Game Programming
    Replies: 2
    Last Post: 03-28-2007, 01:27 PM
  3. Forced moves trouble!!
    By Zishaan in forum Game Programming
    Replies: 0
    Last Post: 03-27-2007, 06:57 PM
  4. Help with my draughts game
    By Zishaan in forum C++ Programming
    Replies: 9
    Last Post: 03-24-2007, 07:33 AM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21