0
0
C++programming~15 mins

Array traversal in C++ - Mini Project: Build & Apply

Choose your learning style9 modes available
Array traversal
📖 Scenario: You are working with a list of daily temperatures recorded over a week. You want to check each temperature to understand the weather pattern.
🎯 Goal: Learn how to go through each item in an array one by one using a loop in C++.
📋 What You'll Learn
Create an array with exact temperature values
Create a variable to hold the number of days
Use a for loop with index variable i to traverse the array
Print each temperature value on its own line
💡 Why This Matters
🌍 Real World
Going through lists of data like temperatures, scores, or prices is common in many programs.
💼 Career
Understanding how to traverse arrays is a basic skill needed for software development, data processing, and many technical jobs.
Progress0 / 4 steps
1
Create the temperature array
Create an integer array called temperatures with these exact values: 23, 25, 22, 20, 19, 21, 24.
C++
Need a hint?

Use curly braces {} to list the values inside the array.

2
Set the number of days
Create an integer variable called days and set it to the number of elements in the temperatures array, which is 7.
C++
Need a hint?

Count the number of values in the array and assign it to days.

3
Traverse the array with a for loop
Use a for loop with the index variable i starting from 0 up to less than days to go through each element in temperatures. Inside the loop, access each temperature using temperatures[i].
C++
Need a hint?

Remember array indexes start at 0 and go up to one less than the number of elements.

4
Print each temperature
Inside the for loop, use std::cout to print each temperature value followed by a newline. This will show all temperatures one by one.
C++
Need a hint?

Use std::cout << temp << std::endl; to print each temperature on its own line.