Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I'm having difficulty looping this program back to the beginning after That number is outside the boundary of the List using System; using static System.Console;

I'm having difficulty looping this program back to the beginning after "That number is outside the boundary of the List"

using System; using static System.Console;

namespace Program { class Program { static void Main() { int[] nums = { 7, 6, 3, 2, 1, 8, 4, 5 }; int choice = 0; const int EXIT = 999; int x; int positionChoice; while (choice != EXIT) { WriteLine("Choose One:"); WriteLine("1 : to view the list in order first to last"); WriteLine("2 : to view the list in order last to first"); WriteLine("3 : choose a specific position to view"); WriteLine("{0} to exit this program", EXIT); Write(""); choice = Convert.ToInt32(ReadLine());

if (choice 3 && choice != EXIT)) ;

switch (choice) { case 1: case 2: WriteLine("--------------------------------"); if (choice == 1) WriteLine("List in Order from First to Last"); else { WriteLine("List in Order from Last to First"); Array.Reverse(nums); } for (x = 0; x 8) { WriteLine("--------------------------------"); WriteLine("What position from 1 to 8 would you like to see: "); positionChoice = Convert.ToInt32(ReadLine()); if (positionChoice 8) WriteLine("That number is outside the boundary of the List", EXIT); } WriteLine(); WriteLine("The List Element in position {1} --> {0}", nums[positionChoice] + 1, positionChoice); break; case EXIT: WriteLine(""); break; default: WriteLine("** Invalid Entry ** - Must choose either 1, 2, 3, or {0} to exit", EXIT); break;

} WriteLine(); } } } }

The end result should look EXACTLY like this:

image text in transcribed

OSYCAWINDOWSlsystem321cmd.exe hoose one: 1 to view the list in order first to last 2 to view the list in order last to first 3 choose a specific position to view 999 to exit this program List in Order from First to Last 7 6 3 2 18 4 5 Choose one: 1 to view the list in order first to last 2 to view the list in order last to first 3 choose a specific position to view 999 to exit this program List in Order from Last to First 5 4 8 1 2 3 6 7 Choose one: 1 to view the list in order first to last 2 to view the list in order last to first 3 choose a specific position to view 999 to exit this program 9 Invalid EntryMust choose either 1, 2, 3 or 999 to exit Choose one: 1 to view the list in order first to last 2 to view the list in order last to first 3 choose a specific position to view 999 to exit this program hat position from 1 to 8 would you like to see: The List Element in position 4 - 2 Choose one: 1 to view the list in order first to last 2 to view the list in order last to first 3 choose a specific position to view 999 to exit this program hat position from 1 to 8 would you like to see: That number is outside the boundary of the List hoose one 1 to view the list in order first to last 2 to view the list in order last to first 3 choose a specific position to view 999 to exit this program

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

Intranet And Web Databases For Dummies

Authors: Paul Litwin

1st Edition

0764502212, 9780764502217

More Books

Students also viewed these Databases questions

Question

How wide are Salary Structure Ranges?

Answered: 1 week ago