Proposed exercise
Create a program in which you write a title (using the previous WriteTitle function) which the user will specify in command line. If no text is specified, your program will display an error message and return a value of 1 to the operatiing system.
Output
Solution
using System;
public class VMain
{
public static void WriteTitle(string text)
{
int numOfSpaces =( 80 - text.Length * 2) / 2;
text = text.ToUpper();
int i = 0;
for(; i < numOfSpaces; i++)
Console.Write(" ");
for(i = 0; i < text.Length * 2 - 1; i++)
Console.Write("-");
Console.WriteLine();
for(i = 0; i < numOfSpaces; i++)
Console.Write(" ");
for(i = 0; i < text.Length; i++)
Console.Write(text[i] + " ");
Console.WriteLine();
for(i = 0; i < numOfSpaces; i++)
Console.Write(" ");
for(i = 0; i < text.Length * 2 - 1; i++)
Console.Write("-");
Console.WriteLine();
}
public static int Main(string[] args)
{
if (args.Length != 1)
{
Console.WriteLine("Faialed option");
return 1;
}
WriteTitle( args[0] );
return 0;
}
}