5 Replies - 719 Views - Last Post: 09 January 2013 - 09:33 PM Rate Topic: -----

#1 Choi Siwon  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 09-January 13

A square of asterisks

Posted 09 January 2013 - 05:03 AM

How can i make a program in dev c++ that ask the user for a number and then it would print a square? Foe example, the user enter 6 so the square will have 6 rows and 6 columns. (Note: using nested loop)

This post has been edited by Atli: 09 January 2013 - 05:11 AM
Reason for edit:: Don't abuse the font size controls! Huge fonts just make your post annoying to read.

Is This A Good Question/Topic? 0
  • +

Replies To: A square of asterisks

#2 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3719
  • View blog
  • Posts: 5,991
  • Joined: 08-June 10

Re: A square of asterisks

Posted 09 January 2013 - 05:16 AM

You would prompt the user for the number, and then use that as the upper limit in your loops. It's not really all that complicated. You just need to do some reading on the basics of C++ to learn how to read and write from the console, and to use a for loop. (It's not even that much reading; this is the kind of stuff most beginner tutorials are likely to cover.)

Attempt it yourself first, and if you can't get it to work, show us what you tried.
Was This Post Helpful? 0
  • +
  • -

#3 Choi Siwon  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 09-January 13

Re: A square of asterisks

Posted 09 January 2013 - 05:59 AM

I cant find something related about my topic problem :(
Was This Post Helpful? 0
  • +
  • -

#4 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3719
  • View blog
  • Posts: 5,991
  • Joined: 08-June 10

Re: A square of asterisks

Posted 09 January 2013 - 06:20 AM

What exactly are you looking for? If you are hoping to find a walk-through tutorial on writing the exact program you are trying to write, I doubt you'll find much. That's not how you research ways to write a program.

Try looking for things about the individual actions: how to read user input, how to print to the console, and how to use for loops. You should have no problems finding material on those things, and once you've learned them, writing the code you are describing should be easy.
Was This Post Helpful? 0
  • +
  • -

#5 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3589
  • View blog
  • Posts: 11,159
  • Joined: 05-May 12

Re: A square of asterisks

Posted 09 January 2013 - 06:26 AM

Actually, if the OP expands his search to look for programs in Pascal, rather than C, he may have more luck. I think this used to be a standard exercise/assignment for beginning Pascal programmers to teach I/O and looping.

But really, the OP should attempt to solve the problem himself before looking for other people's code. Typically when an assignment like this is given, the teacher has already covered enough material about input, output, and loops.
Was This Post Helpful? 0
  • +
  • -

#6 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: A square of asterisks

Posted 09 January 2013 - 09:33 PM

Well, here is a small hint I can give you...I shall create a triangle of *'s...you need to modify it in the correct way to make a square.

int main()
{ 
int i,j;
for ( i = 0; i < 5; i++)
  {
     for (j = 0; j <= i; j++)
       {
           cout<<"*";
       }
     cout<<endl;
  }
return 0;
}



Now this prints

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

You need to make a really small change in the above program and you will get a square..good luck!:)

regards,
Raghav
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1