Нарисовать блок-схему (Сумма всех цифр) - C#

Узнай цену своей работы

Формулировка задачи:

Помогите нарисовать блок-схему. Буду очень благодарен. Вот код:
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Введите первое 4-ёх значное число: ");
            string a = Console.ReadLine();яя
            try
            {
                int x = Convert.ToInt32(a);
            }
            catch
            {
                Console.WriteLine("Ошибка! Введено нодопустимый символ!");
                
                Console.ReadKey();
                return;
            }
            Console.Write("Введите второе 4-ёх значное число: ");
            string b = Console.ReadLine();
            try
            {
                int y = Convert.ToInt32(b);
            }
            catch
            {
                Console.WriteLine("Ошибка! Введено нодопустимый символ!");
                Console.ReadKey();
                return;
            }
            try
            { }
            finally  
            {
                string ab = a + b;
                int il = ab.Length;
                int summ = 0;
                for (int i = 0; i < il; i++)
                {
                    char s = ab[i];
                    string sch = Convert.ToString(s);
                    int ch = Convert.ToInt32(sch);
                    summ = summ+ch;
                }
                Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine("Сумма всех цифр - {0}", summ);
                Console.ReadKey();
            }
        }
    }

Решение задачи: «Нарисовать блок-схему (Сумма всех цифр)»

textual
Листинг программы
static void Main(string[] args)
{
    int a = 0, b = 0;
    if (!GetIntegerValue("Введите первое четырёхзначное число", ref a))
    {
        return;
    }
    if (!GetIntegerValue("Введите второе четырёхзначное число", ref b))
    {
        return;
    }
    Console.WriteLine("Сумма цифр {0} = {1}", a + b, SumOfDigits(a + b));
    Console.Read();
}
 
static int SumOfDigits(int number)
{
    if (number < 10)
    {
        return number;
    }
    return number % 10 + SumOfDigits(number / 10);
}
 
static bool GetIntegerValue(string prompt, ref int value)
{
    while (true)
    {
        Console.Write("{0}: ", prompt);
        var input = Console.ReadLine();
        if (input.Length == 4)
        {
            if (int.TryParse(input, out value))
            {
                break;
            }
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("{0} не является целым числом.", input);
        }
        else
        {
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("{0} не является четырёхзначным числом.", input);
        }
        Console.ResetColor();
        Console.WriteLine("Нажмите любую кнопку для продолжения или Escape для выхода.");
        var key = Console.ReadKey(false);
        if (key.Key == ConsoleKey.Escape)
        {
            return false;
        }
    }
    return true;
}

Оцени полезность:

9   голосов , оценка 4.333 из 5
Похожие ответы