I want the program to continue on running after a user enters an invalid input. When a user inputs a string, an error message displays and then the program closes, however I want the program to continue asking the user to enter a valid input. I tried put the try/catch inside the do/while but it doesn't seem to work for me.
Int16 dollars;
try
{
do
{
Console.WriteLine("Enter a value, or 0 to exit.");
dollars = Convert.ToInt16(Console.ReadLine());
if (dollars >= 1)
{
Console.WriteLine("your current balance is");
myBank.addMoney(dollars);
myBank.getValue();
}
else if (dollars < 0)
{
Console.WriteLine("You have entered a negative number, your current balance is");
myBank.getMoney(dollars);
myBank.getValue();
}
} while (dollars != 0);
}
catch
{
Console.WriteLine("The value you have entered is invalid");
Console.ReadKey();
}