Click here to Skip to main content
15,898,769 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
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");
            }
Posted
Updated 5-Mar-19 4:25am

1 solution

Count the current number of participants, and if the current count == the max permitted, give the user an error message. Seems pretty clear cut to me.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900