outline of square

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Feb 2008
Posts: 25
Reputation: ckins is an unknown quantity at this point 
Solved Threads: 0
ckins ckins is offline Offline
Light Poster

outline of square

 
0
  #1
Feb 14th, 2008
I can make a box with a char quite easily where the user enters two values L, and W using a for loop
but I don't know how to make just the outline. I'm told there are 2 if else statements needed and I've nested my for loop. I don't know how to restrict in the if statement so it will loop char going across, then empty spaces followed by char, then last line gets printed, any help would be appreciated eeee
e e
eeee

for (int myHeight =1;myHeight < width; myHeight++)
{
for (int myBase=1;myBase<length;myBase++)
{
cout <<c;
}
}
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,836
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 503
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: outline of square

 
0
  #2
Feb 14th, 2008
So you want to do something like this?
  1.  
  2. eeeeeeeeeeeeeeeee
  3. e e
  4. e e
  5. e e
  6. eeeeeeeeeeeeeeeee
but don't know how? Or you want this?
  1. eeeeeee
  2. e e e
  3. e e e
  4. eeeeeee
but it ends up like this?
  1. eeeeeee
  2. eee
  3. eee
  4. eeeeeee
Can you elaborate please? I'm not sure what you are trying to do.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 483
Reputation: DangerDev has a spectacular aura about DangerDev has a spectacular aura about 
Solved Threads: 59
DangerDev's Avatar
DangerDev DangerDev is offline Offline
Posting Pro in Training

Re: outline of square

 
-1
  #3
Feb 14th, 2008
use:
  1. for (int myHeight =1;myHeight <width; myHeight++)
  2. {
  3. for (int myBase=1;myBase<length;myBase++)
  4. {
  5. if(myBase==1 || myBase==length-1 )
  6. printf(c);
  7. else if(myHeight==1 || myHeight==width-1)
  8. printf(c);
  9. else
  10. printf(" ");
  11. }
  12. printf("\n");
  13. }
Freedom in the Mind, Faith in the words.. Pride in our Souls...
Indian Developer
http://falaque.wordpress.com/
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 25
Reputation: ckins is an unknown quantity at this point 
Solved Threads: 0
ckins ckins is offline Offline
Light Poster

Re: outline of square

 
0
  #4
Feb 15th, 2008
vernon
it's the top box, the numbers are off int myBase =1, and myHeight=1

I get too many spaces
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,836
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 503
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: outline of square

 
0
  #5
Feb 15th, 2008
Did you try to incorporate any of DangerDev's code? Some of the lines using "printf" had problems, but when fixed, yielded a box that lined up for me. You could either change the "printf" statements to make them work or simply convert the "printf" statements to "cout" statements.

You say you "get too many spaces". In your original code that you posted I don't see you displaying any spaces at all. I am assuming that in this line:
  1. cout << c;
c represents a character and that c is not a space. Please let us know whether you have gotten this working and, if not, please post some updated code.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 114
Reputation: zhelih has a little shameless behaviour in the past 
Solved Threads: 11
zhelih's Avatar
zhelih zhelih is offline Offline
Junior Poster

Re: outline of square

 
0
  #6
Feb 15th, 2008
It is very big mistake to write
  1. printf(c);
Correct is
  1. printf("%c", c);
.
Remember the definition:
  1. printf(argument, ...);
An Apple a Day keeps a Doctor away!
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 25
Reputation: ckins is an unknown quantity at this point 
Solved Threads: 0
ckins ckins is offline Offline
Light Poster

Re: outline of square

 
0
  #7
Feb 27th, 2008
for (int myHeight =0; myHeight< width-2; myHeight++)
{
cout << c;

}

for (int myHeight =0; myHeight< myHeight; myHeight++)
{
for (int myBase =0; myBase< width-2; myBase++)
{
cout << c;

cout << (" ");
}

cout << c;


}

for (int myHeight =0; myHeight< width; myHeight++)
{
cout << c;

cout << endl;
}

return 0;

}
this is what gives me only two sides of the box, I need a whole box
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,836
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 503
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: outline of square

 
0
  #8
Feb 27th, 2008
Originally Posted by ckins View Post
  1. for (int myHeight =0; myHeight< myHeight; myHeight++)
Look at this line. This loop will never be executed due to the condition you have imposed:
  1. myHeight < myHeight
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC