Exercise
Function Write Underlined
Objetive
Create a function able to write centered on screen the text that is indicated as a parameter (supposing a screen width of 80 characters) and then underline it (writing several hyphens under that word):
WriteUnderlined("Hello!");
Example Code
using System;
public class exercise102
{
public static void WriteUnder(string text)
{
int countSpaces = (80 - text.Length) / 2;
int i = 0;
for (; i < countSpaces; i++)
Console.Write(" ");
Console.WriteLine(text);
for (i = 0; i < countSpaces; i++)
Console.Write(" ");
for (i = 0; i < text.Length; i++)
Console.Write("_");
}
public static void Main()
{
WriteUnder("Hello");
}
}