Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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.

This is my code:

But it shows 2/3 correct

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"));} }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Visual Basic 6 Databases

Authors: Charles Williams

1st Edition

1861002025, 978-1861002020

More Books

Students also viewed these Databases questions