Finding the sum of two numbers with C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace odev1
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b;
            string a1, a2;
            Console.Write("First number: ");
            a1 = Console.ReadLine();

            while (true)
            {
                if (int.TryParse(a1, out a))
                {
                    break;
                }
                else
                {
                    Console.Write("No valid value was entered for the first number. Re-enter: ");
                    a1 = Console.ReadLine();
                }
            }

            Console.Write("First number: ");
            a2 = Console.ReadLine();

            while (true)
            {
                if (int.TryParse(a2, out b))
                {
                    break;
                }
                else
                {
                    Console.Write("No valid value was entered for the second number. Re-enter: ");
                    a2 = Console.ReadLine();
                }
            }

            Console.WriteLine("\nFirst number: " + a);
            Console.WriteLine("Second number: " + b);
            Console.WriteLine("Total: " + (a + b));
        }
    }
}

Bir cevap yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir