Console.WriteLine("Mortgage Loan Calculator");
Console.WriteLine("------------------------------------");
C1 c1 = new C1();
while (true)
{
bool continueLoop = true;
do
{
try
{
Console.WriteLine("Enter loan amount: ");
loanAmount = Convert.ToDouble(Console.ReadLine());
checkLoanAmount(loanAmount);
continueLoop = false;
}
catch (FormatException formatException)
{
Console.WriteLine("\n" + formatException.Message);
Console.WriteLine("Please enter a double value. \n");
continueLoop = true;
}
catch (MyRangeException negativeNumberException)
{
Console.WriteLine("\n" + negativeNumberException.test);
}
catch (Exception exception)
{
Console.WriteLine("\n" + exception.Message);
Console.WriteLine("Input string was not in a correct format");
continueLoop = true;
}
} while (continueLoop);
do
{
try
{
Console.WriteLine("Enter loan amount: ");
years = Convert.ToDouble(Console.ReadLine());
checkLoanYears(years);
}
catch (FormatException formatException)
{
Console.WriteLine("\n" + formatException.Message);
Console.WriteLine("Please enter a double value. \n");
}
catch (MyRangeException negativeNumberException)
{
Console.WriteLine("\n" + negativeNumberException.Message);
}
catch (Exception exception)
{
Console.WriteLine("\n" + exception.Message);
Console.WriteLine("Input string was not in a correct format");
}
} while (continueLoop);
do
{
try
{
Console.WriteLine("Enter loan amount: ");
interest = Convert.ToDouble(Console.ReadLine());
checkLoanInterest(interest);
}
catch (FormatException formatException)
{
Console.WriteLine("\n" + formatException.Message);
Console.WriteLine("Please enter a double value. \n");
}
catch (MyRangeException negativeNumberException)
{
Console.WriteLine("\n" + negativeNumberException.Message);
}
catch (Exception exception)
{
Console.WriteLine("\n" + exception.Message);
Console.WriteLine("Input string was not in a correct format");
}
} while (continueLoop);
}
So I'm trying to create a Loan Program with exception handling. I have the code working to where it takes the exceptions when I input in the wrong format. The problem that I'm having though is that it keeps it in an infinite loop asking for the loan amount instead of going to the next question. If anyone could give me some advice of what I'm doing wrong that would be greatly appreciated!