Question: This must be in visual basic C# // A program named SubscriptExceptionTest in which you declare an array of 20 doubles and store values //
This must be in visual basic C#
// A program named SubscriptExceptionTest in which you declare an array of 20 doubles and store values // in the array. Write a try block in which you place a loop that prompts the user for a subscript // value and displays the value stored in the corresponding array position. Create a catch block // that catches any IndexOutOfRangeException and displays an appropriate error message.
namespace SubscriptExceptionTest.cs { class Program { static void Main()
{ int num; bool isValueNum = false; while (!isValueNum)
This is what I have and I keep getting error messages
namespace SubscriptExceptionTest { class Program { public static void main() { int num; bool isNumValue = false; while (!isNumValue) { try { //Ask the user to enter a number
Write(" Enter a number."); num = Convert.ToInt32(ReadLine()); numList.DisplayValue(num); isNumValue = true;
} catch (IndexOutOfRangeException e) { //If the user does not enter a number between 0 and 19, an error message will appear prompting them to try again WriteLine(e.Message + " The value you entered is {0}"); Write("Sorry you must enter a number between 0 and 19"); WriteLine("Please try again and enter another number."); } } }
class numList {
private static double [] value = { 20.01, 20.02, 20.03, 20.04, 20.05, 20.06, 20.07, 20.08, 20.09, 20.10, 20.11, 100.5, 100.6, 100.7, 100.8, 100.9, 100.10, 100.11, 100.12, 999 };
public static void DisplayValue(int num) { //A number appears when the value is within range. WriteLine("The value of your entered number is " + value[num].ToString("C")); } } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
