C#C
C#2y ago
zzz

catching exception but skipping an iteration

using System.Security.Cryptography.X509Certificates;

namespace Caclculator
{
    class Program
    {
        static void Main(string[] args)
        {

            int numTotal;
            int count = 0;

            Console.WriteLine("Welcome to my calculator.");
            Console.WriteLine("How many numbers are in your calculation?");
            numTotal = int.Parse(Console.ReadLine());
            int[] numbers = new int[numTotal];
            while (count < numTotal - 1)
            {
                for (int i = 0; i < numTotal; i++)
                {
                    Console.WriteLine($"Enter number {i + 1}");
                    try
                    {
                        numbers[i] = int.Parse(Console.ReadLine());
                        count = count + 1;
                    }
                    catch (Exception) 
                    {
                        Console.WriteLine("I said a number lil bro :/");
                    }
                }
            }
        }
    }
}

my code works fine other than when the user doesnt input a number and my exception error prints it skips to the next number instead of asking them to reinput it
image.png
Was this page helpful?