943,155 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 671
  • C++ RSS
Feb 8th, 2010
0

drawing a rectangle

Expand Post »
i need help creating a rectangle where the user creates the border and fills in the empty space with any symbol they want.

it should look like this

#######
#@@@@#
#@@@@#
#@@@@#
#######

mine only looks like this

#
@@@@@
#
@@@@@
#
@@@@@

any help??? heres my code:




char b;// character used to draw border of rectangle
char f;//character used to fill the rectangle
cout << "What character would you like to use to draw the border of your rectangle?";
cin >> b;
cout << "What character would you like to use to fill the rectangle?";
cin >> f;
for (int i = 0; i < rectangleLength; i++)
{
cout << b;
cout <<"\n";

for (int j = 0; j < rectangleWidth; j++)
{
cout << f;
}
cout << "\n";
Similar Threads
Reputation Points: 6
Solved Threads: 3
Junior Poster
corby is offline Offline
105 posts
since Feb 2010
Feb 8th, 2010
0
Re: drawing a rectangle
There are two types of lines in your rectangle. The top and bottom line both look alike and all the lines in between have the same appearance. The top and bottom all use the same symbol. The interior lines all have the first and last char the same as the top and bottom line but the interior char are different.

Start out by writing a program that can write a line of the x number of the same char where x is input by user.

Then add code to write a line x char long but both the first and last char are different than all the interior char.

Then use that knowledge to write the real program.
Reputation Points: 718
Solved Threads: 373
Nearly a Posting Maven
Lerner is offline Offline
2,253 posts
since Jul 2005
Feb 8th, 2010
0
Re: drawing a rectangle
First create a function that makes a rectangle like so :
C++ Syntax (Toggle Plain Text)
  1. #######
  2. # #
  3. # #
  4. # #
  5. #######

After you get that , then its a simple change.
Last edited by firstPerson; Feb 8th, 2010 at 5:16 pm.
Reputation Points: 840
Solved Threads: 594
Senior Poster
firstPerson is offline Offline
3,859 posts
since Dec 2008
Feb 8th, 2010
0
Re: drawing a rectangle
USE THE CODE TAGS TO POST YOUR CODE
--------------------------------------------------------------------------------------

We have two lines in the rectangle, as Lerner said, the top and the bottom lines...
So your code should look like this:
1. Draw the top line of the rectangle.
2. Use a loop to draw the other lines simply by printing one character of the borders and then the characters filling the rectange, then the character of the right side of the border.
3. When you reach the bottom Draw it with the border characters.

Try it and if you faced problems, post them and we'll be glad to help....
Reputation Points: 12
Solved Threads: 11
Junior Poster in Training
kim00000 is offline Offline
84 posts
since Oct 2009
Feb 8th, 2010
-2
Re: drawing a rectangle
Wallah
C++ Syntax (Toggle Plain Text)
  1. for( int i = 0; i < Stat.x; i++ )
  2. cout << a;
  3. cout << endl;
  4.  
  5. for( int i = 0; i < Stat.y - 2; i++ )
  6. {
  7. cout << a;
  8. for( int k = 0; k < Stat.x - 2; k++ )
  9. cout << b;
  10. cout << a << endl;
  11. }
  12. for( int i = 0; i < Stat.x; i++ )
  13. cout << a;
A nice shell
Reputation Points: 49
Solved Threads: 6
Junior Poster
VilePlecenta is offline Offline
106 posts
since Jan 2010
Feb 8th, 2010
0
Re: drawing a rectangle
thanks i figured it out
Reputation Points: 6
Solved Threads: 3
Junior Poster
corby is offline Offline
105 posts
since Feb 2010
Feb 8th, 2010
0
Re: drawing a rectangle
thank u bro i cant believe i didnt see that! thanks
Reputation Points: 6
Solved Threads: 3
Junior Poster
corby is offline Offline
105 posts
since Feb 2010
Feb 8th, 2010
0
Re: drawing a rectangle
thanks
Reputation Points: 6
Solved Threads: 3
Junior Poster
corby is offline Offline
105 posts
since Feb 2010
Feb 8th, 2010
0
Re: drawing a rectangle
np, but I recommend the edit button to your posts o:
Reputation Points: 49
Solved Threads: 6
Junior Poster
VilePlecenta is offline Offline
106 posts
since Jan 2010
Feb 8th, 2010
0
Re: drawing a rectangle
now for some reason the program wont work correctly...previously it had worked and created a rectangle and allowed the user to fill in the middle and now it only displays the first line of the rectangle

C++ Syntax (Toggle Plain Text)
  1. for (int i = 0; i < rectangleLength; i++)
  2. {
  3. for (int j = 0; j < rectangleWidth; j++)
  4. {
  5. if ( i == 0 || i == rectangleLength - 1)
  6. {
  7. cout << b;
  8.  
  9. }else if ( j == 0 || j == rectangleWidth - 1)
  10. {
  11. cout << b;
  12. }
  13. else
  14. {
  15. cout << f;
  16. }
  17. }
  18. cout << "\n";
  19. }
Last edited by corby; Feb 8th, 2010 at 10:23 pm.
Reputation Points: 6
Solved Threads: 3
Junior Poster
corby is offline Offline
105 posts
since Feb 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: error C2955 when using list
Next Thread in C++ Forum Timeline: C++ help





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC