473,372 Members | 1,365 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 software developers and data experts.

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;
  7. int main ()
  8. {
  10. int size;
  11. cout<<"Please enter the size of the width of a square: " <<endl;
  12. cin >> size;
  14. for(int i=0;i<size;i++)
  16. {
  18. cout<<'*'<<endl;
  20. }
  21. }
Nov 29 '07 #1
2 6666
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
9,208 Expert Mod 8TB
Have you considered just displaying **** three times??
Nov 29 '07 #3

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

Similar topics

by: Sandman | last post by:
I want to do this: function square ($a){ print "-- $a --"; } And use it like this: <? square( ?> Hello! <? ) ?> And get this:
by: Kim Scarborough | last post by:
Say I wanted to put a couple lines of asterisks between paragraphs, and have it stretch the spaces so that it spanned 100% of the text-width, like this: * * * * * ...
by: ashkaan57 | last post by:
Hi, I was trying to display a small colored square using <table> tag. It worked fine on the screen but when I do print preview, the square shows up as white. I used both: <table width="15"...
by: punkybrewster | last post by:
My task is to write a program that reads in from the user the size of the sides of a square and prints a hollow square of that size in asterisks and spaces. A nested loop should be done. An example...
by: Haines Brown | last post by:
I know I'm missing something obvious. I need a short horizontal rule to preceed a line of text (in a bibliography in which the author is repeated). I tried this: <p> <div class="rule"></div>,...
by: Geekibz | last post by:
Hi.I want to print out a 5 by 5 square of asterisks in c using nested for loops.I tried but my code(see below) resulted in an infinite loop.Pls help. #include<stdio.h> main() { int x,y,c=5;...
by: v4vijayakumar | last post by:
In computer based, two player, board games, how to make computer play? Are there any formal ways to _teach_ computer, to choose best possible move? I know this is kind of off-topic here. Please...
by: yawnmoth | last post by:
According to <http://www.w3schools.com/Css/pr_class_position.asp>, "an element with position: absolute is positioned at the specified coordinates relative to its containing block." I'm trying to...
by: ab12 | last post by:
I'm trying to write a program in C that gets a shape outlined with asterisks from the user, and returns that shape filled with asterisks. It will also get the coordinates of a point inside the shape...
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.