Although Thiago Loureiro's answer solves much of the problem, because it is an exercise, I think it is valid to leave an answer explaining some important points that will clarify your doubts, because it seems to me that the exercise is, in fact, directed to the work with vectors, and an inbound and outbound flow of your program.
There are several errors in your logic and implementation. The vector always has 5 positions with char[] nome_completo = new char[5];
value because at the beginning of your code you declare it this way,
WriteLine()
and never populate, the result is an array of char with 5 empty positions.
The nome_completo
method is for you to write things to the console, not to read information the command below does not assign the input value to your variable:
Console.WriteLine("Digite o seu nome completo: ", nome_completo);
Your application would be in case you already have a declared initial value for Console.ReadLine();
, but it would still not make much sense, here's an example of a more usual application with this overload and a placeholder;
char caractere = 'a'; //poderia ser uma string
Console.WriteLine("Digite o seu nome completo: (iremos contar a quantidade do caractere \"{0}\")", caractere);
See that your ReadLine()
does not assign any value to it and even if you did the input could not be more than 5 characters, because it would exceed the preset limit for your vector and still find an error because the method string
actually returns a type char[]
and not a new char[1024]
, requiring the following conversion:
nome_completo = Console.ReadLine().ToCharArray();
But you'd still find an error, however much you give a larger initial value to your vector, say ReadLine().TocharArray()
and assign its value to nome_completo[conta] != 'conta
'
, your declaration will result in a new error, since now that a value has been assigned to its vector it has no more empty positions and its nome_completo
condition will never be false, resulting in index error because ReadLine()
will continue to be incremented beyond the size of WriteLine()
Then comes your comparison to find the vowel "a", you are testing the character 'a' which is different from 'A' or 'á' or 'ã' and so on. In addition, within the same block you are writing the result as total (which is actually partial) and making the program wait for vogal
.
However, its %code% has a syntax error that does not actually inform the value assigned to the %code% counter. In this case the same technique would be used at the beginning of the response.
//O problema está na "," em '"Total de ",'
//Console.WriteLine("Total de ", vogal + "letras");
Console.WriteLine("Total de {0} letras", vogal);
Below is a review of the code, applying the points noted above, but I recommend that you make changes as shown in the answer so you can better understand the causes and consequences:
static void Main(string[] args)
{
int vogal = 0;
char[] caracteres = { 'a', 'á', 'â', 'ã', 'ä', 'à' };
Console.WriteLine("Digite o seu nome completo:");
char[] nome_completo = Console.ReadLine().ToLower().ToCharArray();
for (int conta = 0; conta < nome_completo.Length; conta++)
{
if (caracteres.Contains(nome_completo[conta]))
{
vogal++;
}
}
Console.WriteLine("Total de {0} letras \"{1}\".", vogal, caracteres[0]);
Console.Read();
Console.ReadKey();
}