Upvote Upvoted 0 Downvote Downvoted
Pls help
posted in Off Topic
1
#1
0 Frags +

I am extremely confused right now
https://drive.google.com/file/d/1uoQ949YXsLJsm0d0Hz0W4BCAiyGrnvBQ/view?usp=sharing
I don't want someone to do my work for me but some pointers for me would be extremely useful I don't really understand how to lookup values in a 2d array(i probably could know it put i didn't go to the class they talked about it).
Here is what I have right now

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace Quiz7
{
    //Coded by 

    public partial class FormCheckDrivingDistance : Form
    {
        public FormCheckDrivingDistance()
        {
            InitializeComponent();
        }
        const int ROWS = 10;
        const int COLS = 10;
        double[,] drivingDistancesArray = {{0, 1004, 1753, 2752, 3017, 1520, 1507, 609, 3155, 448},
 {1004, 0, 921, 1780, 2048, 1397, 919, 515, 2176, 709},
 {1753, 921, 0, 1230, 1399, 1343, 517, 1435, 2234, 1307},
 {2752, 1780, 1230, 0, 272, 2570, 1732, 2251, 1322, 2420},
{3017, 2048, 1399, 272, 0, 2716, 1858, 2523, 1278, 2646},
{1520, 1397, 1343, 2570, 2716, 0, 860, 1494, 3447, 1057},
{1507, 919, 517, 1732, 1858, 860, 0, 1307, 2734, 1099},
{609, 515, 1435, 2251, 2523, 1494, 1307, 0, 2820, 571},
{3155, 2176, 2234, 1322, 1278, 3447, 2734, 2820, 0, 2887},
{448, 709, 1307, 2420, 2646, 1057, 1099, 571, 2887, 0}};

        private void buttonCalculate_Click(object sender, EventArgs e)
        {
            String comboBoxValue1 = comboBoxDeparture.Text;
            //set the picture shown in the picture box to the corresponding one 
            //that was set 

            if (comboBoxValue1 == "Boston" )
            {
                pictureBox1.Image = imageList1.Images[0];
            }
            if (comboBoxValue1 == "Chicago")
            {
                pictureBox1.Image = imageList1.Images[1];
            }
            if (comboBoxValue1 == "Dallas")
            {
                pictureBox1.Image = imageList1.Images[2];
            }
            if (comboBoxValue1 == "Las Vegas")
            {
                pictureBox1.Image = imageList1.Images[3];
            }
            if (comboBoxValue1 == "Los Angeles")
            {
                pictureBox1.Image = imageList1.Images[4];
            }
            if (comboBoxValue1 == "Miami")
            {
                pictureBox1.Image = imageList1.Images[5];
            }
            if (comboBoxValue1 == "New Orleans")
            {
                pictureBox1.Image = imageList1.Images[6];
            }
            if (comboBoxValue1 == "Toronto")
            {
                pictureBox1.Image = imageList1.Images[7];
            }
            if (comboBoxValue1 == "Vancouver")
            {
                pictureBox1.Image = imageList1.Images[8];
            }
            if (comboBoxValue1 == "Washington DC")
            {
                pictureBox1.Image = imageList1.Images[9];
            }
           if(comboBoxValue1 == null)
            {
                MessageBox.Show("Please enter departure city");

            }
            String comboBoxValue2 = comboBoxDestination.Text;
            //set the picture shown in the picture box to the corresponding one 
            //that was set 

            if (comboBoxValue2 == "Boston")
            {
                pictureBox2.Image = imageList1.Images[0];
            }
            if (comboBoxValue2 == "Chicago")
            {
                pictureBox2.Image = imageList1.Images[1];
            }
            if (comboBoxValue2 == "Dallas")
            {
                pictureBox2.Image = imageList1.Images[2];
            }
            if (comboBoxValue2 == "Las Vegas")
            {
                pictureBox2.Image = imageList1.Images[3];
            }
            if (comboBoxValue2 == "Los Angeles")
            {
                pictureBox2.Image = imageList1.Images[4];
            }
            if (comboBoxValue2 == "Miami")
            {
                pictureBox2.Image = imageList1.Images[5];
            }
            if (comboBoxValue2 == "New Orleans")
            {
                pictureBox2.Image = imageList1.Images[6];
            }
            if (comboBoxValue2 == "Toronto")
            {
                pictureBox2.Image = imageList1.Images[7];
            }
            if (comboBoxValue2 == "Vancouver")
            {
                pictureBox2.Image = imageList1.Images[8];
            }
            if (comboBoxValue2 == "Washington DC")
            {
                pictureBox2.Image = imageList1.Images[9];
            }
           if(comboBoxValue2 == null)
            {
                MessageBox.Show("Please enter destination city");

            }
            String comboBoxValue3 = comboBoxTotalDistance.Text;

        }

        private void buttonClear_Click(object sender, EventArgs e)
        {
            //clear the comboboxes and output labels

        }

        private void buttonExit_Click(object sender, EventArgs e)
        {
            //close the application
            this.Close();
        }

        private void FormCheckDrivingDistance_Load(object sender, EventArgs e)
        {
            pictureBox1.Image = imageList1.Images[0];
            pictureBox2.Image = imageList1.Images[0];
        }
    }
}
I am extremely confused right now
https://drive.google.com/file/d/1uoQ949YXsLJsm0d0Hz0W4BCAiyGrnvBQ/view?usp=sharing
I don't want someone to do my work for me but some pointers for me would be extremely useful I don't really understand how to lookup values in a 2d array(i probably could know it put i didn't go to the class they talked about it).
Here is what I have right now
[code]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace Quiz7
{
//Coded by

public partial class FormCheckDrivingDistance : Form
{
public FormCheckDrivingDistance()
{
InitializeComponent();
}
const int ROWS = 10;
const int COLS = 10;
double[,] drivingDistancesArray = {{0, 1004, 1753, 2752, 3017, 1520, 1507, 609, 3155, 448},
{1004, 0, 921, 1780, 2048, 1397, 919, 515, 2176, 709},
{1753, 921, 0, 1230, 1399, 1343, 517, 1435, 2234, 1307},
{2752, 1780, 1230, 0, 272, 2570, 1732, 2251, 1322, 2420},
{3017, 2048, 1399, 272, 0, 2716, 1858, 2523, 1278, 2646},
{1520, 1397, 1343, 2570, 2716, 0, 860, 1494, 3447, 1057},
{1507, 919, 517, 1732, 1858, 860, 0, 1307, 2734, 1099},
{609, 515, 1435, 2251, 2523, 1494, 1307, 0, 2820, 571},
{3155, 2176, 2234, 1322, 1278, 3447, 2734, 2820, 0, 2887},
{448, 709, 1307, 2420, 2646, 1057, 1099, 571, 2887, 0}};

private void buttonCalculate_Click(object sender, EventArgs e)
{
String comboBoxValue1 = comboBoxDeparture.Text;
//set the picture shown in the picture box to the corresponding one
//that was set

if (comboBoxValue1 == "Boston" )
{
pictureBox1.Image = imageList1.Images[0];
}
if (comboBoxValue1 == "Chicago")
{
pictureBox1.Image = imageList1.Images[1];
}
if (comboBoxValue1 == "Dallas")
{
pictureBox1.Image = imageList1.Images[2];
}
if (comboBoxValue1 == "Las Vegas")
{
pictureBox1.Image = imageList1.Images[3];
}
if (comboBoxValue1 == "Los Angeles")
{
pictureBox1.Image = imageList1.Images[4];
}
if (comboBoxValue1 == "Miami")
{
pictureBox1.Image = imageList1.Images[5];
}
if (comboBoxValue1 == "New Orleans")
{
pictureBox1.Image = imageList1.Images[6];
}
if (comboBoxValue1 == "Toronto")
{
pictureBox1.Image = imageList1.Images[7];
}
if (comboBoxValue1 == "Vancouver")
{
pictureBox1.Image = imageList1.Images[8];
}
if (comboBoxValue1 == "Washington DC")
{
pictureBox1.Image = imageList1.Images[9];
}
if(comboBoxValue1 == null)
{
MessageBox.Show("Please enter departure city");

}
String comboBoxValue2 = comboBoxDestination.Text;
//set the picture shown in the picture box to the corresponding one
//that was set

if (comboBoxValue2 == "Boston")
{
pictureBox2.Image = imageList1.Images[0];
}
if (comboBoxValue2 == "Chicago")
{
pictureBox2.Image = imageList1.Images[1];
}
if (comboBoxValue2 == "Dallas")
{
pictureBox2.Image = imageList1.Images[2];
}
if (comboBoxValue2 == "Las Vegas")
{
pictureBox2.Image = imageList1.Images[3];
}
if (comboBoxValue2 == "Los Angeles")
{
pictureBox2.Image = imageList1.Images[4];
}
if (comboBoxValue2 == "Miami")
{
pictureBox2.Image = imageList1.Images[5];
}
if (comboBoxValue2 == "New Orleans")
{
pictureBox2.Image = imageList1.Images[6];
}
if (comboBoxValue2 == "Toronto")
{
pictureBox2.Image = imageList1.Images[7];
}
if (comboBoxValue2 == "Vancouver")
{
pictureBox2.Image = imageList1.Images[8];
}
if (comboBoxValue2 == "Washington DC")
{
pictureBox2.Image = imageList1.Images[9];
}
if(comboBoxValue2 == null)
{
MessageBox.Show("Please enter destination city");

}
String comboBoxValue3 = comboBoxTotalDistance.Text;

}

private void buttonClear_Click(object sender, EventArgs e)
{
//clear the comboboxes and output labels

}

private void buttonExit_Click(object sender, EventArgs e)
{
//close the application
this.Close();
}

private void FormCheckDrivingDistance_Load(object sender, EventArgs e)
{
pictureBox1.Image = imageList1.Images[0];
pictureBox2.Image = imageList1.Images[0];
}
}
}

[/code]
2
#2
3 Frags +

stop trying to hack me

stop trying to hack me
3
#3
match.tf
2 Frags +

I've never touched C#, but what exactly is your problem? If it is just looking for a value in a 2d array, simply assign cities to indexes [0-9], let user pick X and Y, then read a result as drivingDistancesArray[X, Y].

Also, please do not use that much of ifs regardless of the language. C-like languages do have the switch operator, I guess?

I've never touched C#, but what exactly is your problem? If it is just looking for a value in a 2d array, simply assign cities to indexes [0-9], let user pick X and Y, then read a result as drivingDistancesArray[X, Y].

Also, please do not use that much of ifs regardless of the language. C-like languages do have the switch operator, I guess?
4
#4
0 Frags +

https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/arrays/multidimensional-arrays

documentationSimilarly, the following example gets the value of a particular array element and assigns it to variable elementValue.

C#

int elementValue = array5[2, 1];
https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/arrays/multidimensional-arrays
[quote=documentation]Similarly, the following example gets the value of a particular array element and assigns it to variable elementValue.

C#

int elementValue = array5[2, 1];[/quote]
5
#5
0 Frags +

So basically my problem is that I need to pick the specific values from the array that correspond to the value that I chose from the combined drop down

So basically my problem is that I need to pick the specific values from the array that correspond to the value that I chose from the combined drop down
6
#6
1 Frags +
IntricateSo basically my problem is that I need to pick the specific values from the array that correspond to the value that I chose from the combined drop down

Think of an array as a list of lists, so instead of calling the result of column 1 row 1, you're getting the result of the first item of the first list, and so on. If you think about it this way, you should realize that you need to get the value of the departure city to figure out what list to look at, and the value of the destination city to figure out what value to look at in that list. From there, the code basically writes itself.

Also, like #3 said, learn the switch operator, love the switch operator, it will save you a TON of writing. In this case I'd have the source and destination cities set variables that you use to look up the picture and the distance at the same time. You could probably save space by making a function that accepts the cities as args and returns the array index and picture, so you can just call that twice for the departure and destination dropdowns. Compact, modular, extensible design is better than repeating the same code a bunch, even if the end product functions the same.

Now I want to start coding again, so thanks for that.

[quote=Intricate]So basically my problem is that I need to pick the specific values from the array that correspond to the value that I chose from the combined drop down[/quote]

Think of an array as a list of lists, so instead of calling the result of column 1 row 1, you're getting the result of the first item of the first list, and so on. If you think about it this way, you should realize that you need to get the value of the departure city to figure out what list to look at, and the value of the destination city to figure out what value to look at in that list. From there, the code basically writes itself.

Also, like #3 said, learn the switch operator, love the switch operator, it will save you a TON of writing. In this case I'd have the source and destination cities set variables that you use to look up the picture and the distance at the same time. You could probably save space by making a function that accepts the cities as args and returns the array index and picture, so you can just call that twice for the departure and destination dropdowns. Compact, modular, extensible design is better than repeating the same code a bunch, even if the end product functions the same.

Now I want to start coding again, so thanks for that.
7
#7
0 Frags +

At this stage just think about the 2D array as just the table of driving distances.

When you as a human want to look up the distance between the two cities you first have to find what two cities you have to find the distance from.
With those two cities just read the table and find the distance between the two cities. When you read the table you take one of the cities names and find the row then take the other cities name and find the corresponding column. Where the column and the row intersect you find the distance. Doing this programmatically is not much different.

Like when you looked into 1D arrays the number tells the computer what slot to look into i.e. int z = array[2].
However 2D arrays are like the table. you need both the row and the column to get what data is inside it.
For example if you want to find the distance between Dallas and Boston you would go int p = drivingDistancesArray[0,2]

As Dallas is the 0 row and Boston is in the 2 Column( Remember arrays in C# start at 0(there is a reason why but its complex)).
What your job is to do is to find a way to programmatically look up the table.

At this stage just think about the 2D array as just the table of driving distances.

When you as a human want to look up the distance between the two cities you first have to find what two cities you have to find the distance from.
With those two cities just read the table and find the distance between the two cities. When you read the table you take one of the cities names and find the row then take the other cities name and find the corresponding column. Where the column and the row intersect you find the distance. Doing this programmatically is not much different.

Like when you looked into 1D arrays the number tells the computer what slot to look into i.e. int z = array[2].
However 2D arrays are like the table. you need both the row and the column to get what data is inside it.
For example if you want to find the distance between Dallas and Boston you would go int p = drivingDistancesArray[0,2]

As Dallas is the 0 row and Boston is in the 2 Column( Remember arrays in C# start at 0(there is a reason why but its complex)).
What your job is to do is to find a way to programmatically look up the table.
Please sign in through STEAM to post a comment.