I'm still a beginner to programming in high-level programming languages, so I don't know if this is an easy solution, but I'm happy to learn anyway. I've programmed a little alarm program in C# that let's the user input in how many seconds the alarm needs to go off. It works perfectly, but the input that the user needs to give has to be a number. When the user inputs any form of text, the program crashes. Now, how can I prevent that users input text, and call a function or do something else when the user does, instead of the program just crashing?
This is the code I have now:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Test
{
class Alarm
{
public static void play()
{
int sec;
sec = Convert.ToInt16(Console.ReadLine());
for (int i = 0; i < seconds; ++i)
{
System.Threading.Thread.Sleep(1000);
}
for (int i = 0; i < 10; i++)
{
Console.Beep();
}
}
}
}