As requested, the ungolfed version:
string ug(int n) {
// The sting we'll be returning
string ret = "";
// The width and height of the output
int s = n * 2 + 1;
// for loop for width and height
for (int height = 0; height < s; height++)
{
for (int width = 0; width < s; width++)
{
// Matches on top-left to bottom-right diagonal line
if (height == width)
{
// If this is the center, write the 'sun'
if (width == n)
{
ret += "O";
}
// If this is not the center, add the diagonal line character
else
{
ret += "\\";
}
}
// Matches on top-right to bottom-left diagonal line
else if (width == s - height - 1)
{
ret += "/";
}
// Matches to add the center line
else if (width == n)
{
ret += "|";
}
// Matches to add the horizontal line
else if (height == n)
{
ret += "-";
}
// Matches all others
else
{
ret += " ";
}
}
// Add a newline to separate each line
ret += "\n";
}
return ret;
}
This is my first post so apologies if I've done something wrong. Any comments and corrections are very welcome.