Skip to content
Number counter broken
Profile icon

This is a simple number counter I made in C#, but if you put in a number that is too high, it stops before finishing. Can someone help me?

You are viewing a single comment. View All
Profile icon

ok, based on what people say,

using System; using System.Collections.Generic; class Program { static void Main (string[] args) { List<int> numbers = new List<int>(); try { Console.WriteLine("What number do you want me to count to?"); int answer = Convert.ToInt32(Console.ReadLine()) + 1; for (int i = 0 ; i < answer; i++) { numbers.Add(i); Console.WriteLine(numbers[i]); } Console.WriteLine(" "); Console.WriteLine($"Succesfully counted to {answer - 1}"); Console.WriteLine(" "); Console.WriteLine(" "); Console.WriteLine(" "); } catch { Console.WriteLine("Number too high"); } } }