Question match capital city and country?

*VLORI*

New member
Joined
Apr 20, 2013
Messages
1
Programming Experience
Beginner
[h=5]Plss can u help me about this how to make when I select the Capital City Madrid and City Spain to show me True or when I select Paris and France again True,,, and if I select Paris and Germany to show False ?[/h]922732_4818499742531_1310944714_n.jpg


I have written these code but only for Madrid & Spain, how to make it works as well for others ( Paris with France, Berlin with Germany)?????

C#:
[/FONT][/COLOR][COLOR=#333333][FONT=lucida grande] [/FONT][/COLOR][COLOR=#333333][FONT=lucida grande]namespace example1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
listBox1.Items.Add("Madrid"); listBox1.Items.Add("Paris"); listBox1.Items.Add("Berlin");
listBox2.Items.Add("France"); listBox2.Items.Add("Germany"); listBox2.Items.Add("Spain");
}

private void ptToolStripMenuItem_Click(object sender, EventArgs e)
{
listBox1.Font = new Font(listBox1.Font.FontFamily, 20);
listBox2.Font = new Font(listBox2.Font.FontFamily, 20);
}

private void button1_Click(object sender, EventArgs e)
{

if ((string)listBox1.SelectedItem == "Madrid" && (string)listBox2.SelectedItem == "Spain")
MessageBox.Show("True","",MessageBoxButtons.OK, MessageBoxIcon.Information);
else
MessageBox.Show("False", "",MessageBoxButtons.OK, MessageBoxIcon.Error);

}
}
}[/FONT][/COLOR][COLOR=#333333][FONT=lucida grande]
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
3,130
Location
Sydney, Australia
Programming Experience
10+
You need to create some sort of relationship between the cities and the countries so that you can test whether what the user has selected matches that. One option would be concurrent arrays, where you would put the cities in one array and the countries in another in the corresponding order. When the user selects a city, you can get the index of that city in the first array and then use that index to find the corresponding country from the second array and compare that to what the user selected.
 
Top Bottom