Hello RaiN3772,
Now that you have it working, if I may offer some suggestions:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
for (int row = 1; row <= length; row++)
{
for (int col = 1; col <= length; col++)
{
if (row == col && col == (length + 1) - row)
{
std::cout << "| ";
}
else if (row == col)
{
std::cout << "\\ ";
}
else if (col == (length + 1) - row)
{
std::cout << "/ ";
}
else
{
std::cout << "* ";
}
}
std::cout << std::endl;
}
|
When it comes to giving the loop iterator a name "i" and "j" are most often used, but if you call then "row" and "col" you will find the rest of your code easier to understand and follow. Making the code easy to read and understand will first benefit you then others later. Also some well placed blank lines will make the code easier to read, e.g.,
1 2 3 4 5 6 7 8 9 10 11
|
int main()
{
int length;
cout << "Please enter the Square's Length: ";
cin >> length;
draw_square(length);
return 0;
}
|
With Time and practice you will figure out what works best for you.
I am guessing English is not your first language because it is spelled "length" to be correct. To the compiler is makes no difference as long as it is spelled the same everywhere you use it.
Your use of the {}s is fine. Just be consistent in their use. Do not mix different styles. As you notice the style I use is easier to read and that pert is what is most important.
You can see different styles of {}s at
https://en.wikipedia.org/wiki/Indentation_style#Brace_placement_in_compound_statements The "Allman" style is what I prefer, but you are free to use what you have learned and are use to. I am not saying that you need to change what you have learned.
Just a small thing. When an if/else if/else only has one line the {}s are not needed. Some will use them in case later they need to add something. Either way it makes no difference. This also applies to for loops and while loops.
Andy