Using a two-dimensional and one-dimensional array, create a program that will display the cost of a Bahamasair ticket given the FROM and TO locations. The cities/towns to use for this program:Nassau, Freeport, harbour island and marsh harbour

Recommended Answers

All 5 Replies

We won't do your homework for you, but if you show us what you have tried so far and where you are stuck perhaps we can help.

string[,] island = new string[4, 1];
        island[0, 0] = "Nassau" + "210";
        island[1, 1] = "Freeport" + "$350";
        island[2, 2] = "HarbourIsland" + "$400";
        island[3, 3] = "MarshHarbour" + "$275";

        for (int i = 0; i <= 3; i++)

        {
            string element = island[i, 0];
            Console.WriteLine("{1}-, {0}", i, element);

        }

        {
            Console.WriteLine("Select the from town 0-3,");

        }
        Console.ReadLine();
        Console.WriteLine("You have chosen {2}", island);
        {
            Console.WriteLine("Please select To location 0-3");

It is giving me an error saying array index out of bounds

You declare the dimensions of island as [4,1] but you index the columns as 0, 1, 2, 3 (lines 2-5). Did you mean to do

island[0, 0] = "Nassau" + "210";
island[1, 0] = "Freeport" + "$350";
island[2, 0] = "HarbourIsland" + "$400";
island[3, 0] = "MarshHarbour" + "$275";

Okay I see what you’re say so it’ll have to be 4,4

Only if you want the entries to be along the diagonal like

x - - -
- x - -
- - x -
- - - x
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.