本文介绍了如何使用全局变量来限制列表框的输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
You are required to create an application for the BestMed race to assist in racers to register.
The racer should type in their name, select a race type and enter their age. The racer should then
be added to a listbox.The race types are as follows:
5Km
10Km
42.5Km
The following rules apply when adding a participant to a race:
If a racer is over the age of 65 they can only participate in the 5km race
Each race can only have a maximum of 10 participants (Hint – Use global variable to
keep track of number of participants)
You should also ensure that the number of participants for the selected race does not
exceed ten, if it does then you should display a messageBox informing the user that the
race is full.
I dont know how to limit the participants.
What I have tried:
<pre lang="c#"><pre> private void btnAddToRace_Click(object sender, EventArgs e)
{
// declare variables and assign values
string name = txtName.Text;
string RaceType = cbxRaceType.Text;
int age;
// get users age
age = Convert.ToInt32(txtAge.Text);
if(age >= 65 && cbxRaceType.Text != "5 Km") //ensure participants aged 65 only enters for 5Km
{
MessageBox.Show("You can only register for the 5Km race, beacuase you are 65 or older");
}
else
{
lstRace.Items.Add(name + RaceType + "Race");
}
推荐答案
这篇关于如何使用全局变量来限制列表框的输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!