Question: What I need: In C#: Write the program SubscriptExceptionTest in which you use an array of 10 doubles. Write a try block in which you
What I need:
In C#: Write the program SubscriptExceptionTest in which you use an array of 10 doubles. 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 or asks the user to quit the program by entering 99. Create a catch block that catches any IndexOutOfRangeException and displays the message:
Index was outside the bounds of the array.
What I have:
using System; public class SubscriptExceptionTest { public static void Main() {bool isNumValue = false; int num=0; do {try {Console.Write(" Enter a number."); num = Convert.ToInt32(Console.ReadLine()); numList.DisplayValue(num); isNumValue=true;} catch (IndexOutOfRangeException e) {Console.WriteLine(e.Message + " The value you entered is {0}",num); Console.WriteLine("Index was outside the bounds of the array"); isNumValue=false;}} while(isNumValue);} } class numList { private static double [] value = {20.3, 44.6, 32.5, 46.7, 89.6, 67.5, 12.3, 14.6, 22.1, 13.6}; public static void DisplayValue(int num) {Console.WriteLine("The value of your entered number is " + value[num].ToString("C"));} }
Problem:
I need it to implement that the application stops asking for new numbers when 99 is entered instead of saying it is outside of the array,
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
