0
0
C++programming~20 mins

Continue statement in C++ - Mini Project: Build & Apply

Choose your learning style9 modes available
Using the Continue Statement in C++
📖 Scenario: Imagine you are organizing a small race event. You have a list of runners with their ages. You want to print the names of only the adult runners (age 18 or older) who are allowed to participate.
🎯 Goal: Build a C++ program that uses the continue statement inside a for loop to skip runners who are under 18 years old and print only the names of adult runners.
📋 What You'll Learn
Create a list of runners with their ages using an array of structs
Use a variable to store the minimum age allowed (18)
Use a for loop to go through each runner
Use the continue statement to skip runners younger than 18
Print the names of runners who are 18 or older
💡 Why This Matters
🌍 Real World
Filtering lists of people or items based on conditions is common in many programs, such as event management, user access control, or data processing.
💼 Career
Understanding how to control loops and skip unwanted data is a fundamental skill for software developers, especially when working with collections of data.
Progress0 / 4 steps
1
Create the runners data
Create a struct called Runner with two members: name (string) and age (int). Then create an array called runners with these exact entries: {"Alice", 17}, {"Bob", 20}, {"Charlie", 16}, {"Diana", 22}.
C++
Need a hint?

Use struct to define Runner. Then create an array with the exact runners and ages.

2
Set the minimum age allowed
Create an int variable called min_age and set it to 18.
C++
Need a hint?

Just create a simple integer variable named min_age and assign 18 to it.

3
Use a for loop with continue to skip underage runners
Write a for loop that goes through each runner in runners. Inside the loop, use an if statement to check if the runner's age is less than min_age. If yes, use continue to skip to the next runner.
C++
Need a hint?

Use a for loop with index i from 0 to 3. Inside, check age and use continue to skip underage runners.

4
Print the names of adult runners
Inside the for loop, after the continue statement, add a std::cout statement to print the runner's name followed by a newline.
C++
Need a hint?

Use std::cout << runners[i].name << std::endl; to print the name of each adult runner.