May 2, 2016 at 5:13am UTC
I'm in a beginner C++ class and need some help with an assignment.
The program needs to accept an integer and then print out a square with side lengths equal to the integer using 0's.
Ex)
Input = 4
Output =
0000
0000
0000
0000
or
Input = 2
Output =
00
00
Here is what I have so far:
int main()
{
int length;
cin >> length;
for (int count = length; count != 0; count--)
{
cout << "0";
}
cout << endl;
return 0;
}
* So I have a single line with the correct number of 0's based on the input but I can't think of a way to then make that line print out multiple times (the correct number of times based on the input). If anyone could point me in the right direction I'd be very grateful!
Last edited on May 2, 2016 at 5:14am UTC
May 2, 2016 at 5:21am UTC
You'll need a double nested loop (a loop within a loop).
The inner loop will print the rows, while the outer loop will print the columns. Make sure to cout a new line after the inner loop.
May 2, 2016 at 5:27am UTC
I thought I had done that but I gave it another try and it worked. Thanks for your help Arsian7041!