Instruction:
Input a string from the user. The program will check to ensure that the string
has a length in the range of 2 to 10 characters (inclusive). If the user entered an
incorrect string, error messages for each error will be displayed(example below)
specifying the type of error, and a loop will be used to input a new string.
must use a for loop to do this.
Output should be.
Stringy
Enter a string: a
Error, the string is too short.
Enter a string: 123456789abc
Error, the string is too long.
Enter a string: ok string
o
k
s
t
r
i
n
g
Press any key to exit:
For program, i know how to use it a foreach loop
but that in a for loop and i don't know how to put a limit range in a string.
My code is:
static void Main(string[] args)
{
string sName;
Console.Title = "Stringy";
Console.WriteLine("{0, 40}", "Stringy");
Console.Write("Enter a string: ");
sName = Console.ReadLine();
foreach (char cValue in sName)
{
Console.WriteLine(cValue);
}
Console.WriteLine("Press any key to exit");
Console.ReadLine();
}