Hello everyone,
I'm taking a c# course in college and still fairly new to the language so please bear with me on this one. I'm working on an assignment that is based solely on iterations and decision statements in a Visual Studio Console app, and essentially what I'm trying to do is create a hollow square with asterisks and have the user input a message that will read in the center of the square. The user must also input the width of the square and once everything is printed, they will be prompted again to write a message and input the width until they want to exit. I've been watching countless videos on loops and have spent an unhealthy amount of hours trying to get everything to line up properly, i'm slowly losing my mind.
This is what I have so far:
I appreciate any and all help, thanks in advance.
I'm taking a c# course in college and still fairly new to the language so please bear with me on this one. I'm working on an assignment that is based solely on iterations and decision statements in a Visual Studio Console app, and essentially what I'm trying to do is create a hollow square with asterisks and have the user input a message that will read in the center of the square. The user must also input the width of the square and once everything is printed, they will be prompted again to write a message and input the width until they want to exit. I've been watching countless videos on loops and have spent an unhealthy amount of hours trying to get everything to line up properly, i'm slowly losing my mind.
This is what I have so far:
C#:
static void Main(string[] args)
{
Console.WriteLine("Enter a message:");
string msg = Console.ReadLine();
Console.WriteLine("Enter a width:");
int width = int.Parse(Console.ReadLine());
for (int k = 1; k < width; k++)
{
Console.Write("*");
}
for (int i = 0; i < 4; i++)
{
Console.WriteLine("*");
for (int j = 0; j < width; j++)
{
Console.Write(" ");
if (i == 1)
{
for (int k = 1; k < msg.Length; k++)
{
Console.Write(" ");
Console.Write(msg);
break;
}
}
}
Console.WriteLine("*");
Console.WriteLine();
}
for (int l = 0; l < width; l++)
{
Console.Write("*");
}
Console.ReadLine();
}
Last edited by a moderator: