Working with One-Dimensional Arrays in C++
📖 Scenario: You are helping a small store keep track of the prices of five products. You will use a one-dimensional array to store these prices and then calculate the total cost.
🎯 Goal: Create a program that stores product prices in an array, calculates the total price, and prints the total.
📋 What You'll Learn
Create a one-dimensional array called
prices with exactly five double values: 10.5, 23.0, 7.25, 15.0, and 9.99Create a variable called
total of type double and initialize it to 0Use a
for loop with the variable i to iterate over the prices arrayAdd each price to the
total inside the loopPrint the
total with the message Total price: 💡 Why This Matters
🌍 Real World
Stores and shops often use arrays to keep track of product prices or quantities.
💼 Career
Understanding arrays and loops is essential for programming tasks like data processing, inventory management, and financial calculations.
Progress0 / 4 steps