468,512 Members | 1,402 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,512 developers. It's quick & easy.

Making a Block Square with Asterisks

Hi could you help me, I want to write a program that Writes a function that displays at the left margin of the screen a solid square of asterisks whose
side is specified in integer parameter side. For example, if side is 4, the function displays:


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

But my code i have made has got me this when i put 4 in, do i need to put another for statment somewhere??

*
*
*
*

Heres my code, I was thinking that maybe I should put some kind of for statement inside the loop to make a nested loop but im not sure what statement would get me the output i need

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using std::cout;
  3. using std::cin;
  4. using std::endl;
  5.  
  6.  
  7. int main ()
  8. {
  9.  
  10. int size;
  11. cout<<"Please enter the size of the width of a square: " <<endl;
  12. cin >> size;
  13.  
  14. for(int i=0;i<size;i++)
  15.  
  16. {
  17.  
  18. cout<<'*'<<endl;
  19.  
  20. }
  21. }
Nov 29 '07 #1
2 6292
Yes, you need a outer loop running till (size-1).
You also need to remove the endl operator from its present place and use it twice between the loops.
Nov 29 '07 #2
weaknessforcats
9,207 Expert Mod 8TB
Have you considered just displaying **** three times??
Nov 29 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

6 posts views Thread by Sandman | last post: by
22 posts views Thread by Kim Scarborough | last post: by
7 posts views Thread by ashkaan57 | last post: by
14 posts views Thread by Haines Brown | last post: by
Geekibz
3 posts views Thread by Geekibz | last post: by
14 posts views Thread by v4vijayakumar | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.