For Loops and Arrays
Learn C++ for loops and arrays by building a weekly step tracker that calculates the total and average steps over 7 days.
The project
You’ve already created a step tracker that records daily steps, but right now it only works when you enter the numbers manually. Printing a single line like: Steps today: 3,000, can be helpful, but it doesn’t show your progress over an entire week.
To make the tracker more useful, you need a system that stores seven days of step counts in a list and then loops through them to calculate both the total and the average.
Your project: build a weekly step tracker that keeps 7 days of steps in an array, uses a loop to add them up, and calculates the average steps per day.
The programming concept
A while loop repeats while a condition is true. But sometimes you already know exactly how many times you want something to be repeated. For example: Say hello for 5 times. Do you think a for loop or a while loop is more natural for that?
C++ gives us both. Let’s start with the ...