Console.Write("Digite um numero de 4 digitos: ");
string numero = Convert.ToString(Console.ReadLine());
int soma = 0;
for(int i = 0; i < numero.Length; i++)
{
soma += Convert.ToInt32(numero[i]);
}
Console.WriteLine("Soma dos numeros = "+soma);
I know that your put to convert the whole number ( Convert.ToInt32(numero)
) converts normally, but when converting only the positions, the program converts string
to HTML code, according to the Unicode table, type, 2 = 50, 3 = 51
, all wrong. How do I convert each value from string
to int
?