This code is supposed to output a hollow square (size and symbols to be determined by the user), but it doesn't do that. First of all, if I set the size of the square to be 5, it outputs 10-5 sets of both symbols. Also the right column is in the middle of the square, not at the end. So right now my square of size 5 looks like this:
* + * + * + * + * +
* + * +
* + * +
* + * +
* + * + * + * + * +
I need it to look like this:
* + * + *
+ +
* *
+ +
* + * + *
Here is the code I have so far:
#include<iostream>
using namespace std;
int main()
{
cout << "Please enter a size for the square: ";
int size;
cin >> size;
cout << "Please enter first symbol: ";
char sym1;
cin >> sym1;
cout << "Please enter a second symbol: ";
char sym2;
cin >> sym2;
for (int row=1; row<=size; row++)
{
for (int col=1; col<=size; col++)
{
if (row>1 && row<size && col>1 && col<size)
cout << " ";
else
cout << sym1 << " " << sym2 << " ";
}
cout << "\n";
}
return 0;
}
What am I doing wrong?