Hello, I’m working on this task:
Write a program that reads an integer count, for the number of characters to read, from the console. Then, from a new line, the program should read count characters written in one line from the console. Finally, the program should output only the letters from the characters to the console on one line. For example:
>10
>FL45H0b12c
FLHbc
Here is my code:
namespace CharType
{
class OnlyLetters
{
static void Main(string[] args)
{
int count = int.Parse(Console.ReadLine());
for (int i = 0; i < count; i++)
{
char firstChar = Convert.ToChar(Console.Read());
if (char.IsLetter(firstChar))
{
Console.Write(firstChar);
}
char secondChar = Convert.ToChar(Console.Read());
if (char.IsLetter(secondChar))
{
Console.Write(secondChar);
}
}
}
}
}
Can anyone please help me to solve it?
I am getting a System.OverflowException: value was either too large or too small for a character error.
Works in Visual Studio, however.