0
0
Goprogramming~15 mins

Array initialization in Go - Mini Project: Build & Apply

Choose your learning style9 modes available
Array initialization
📖 Scenario: You are working on a simple inventory system for a small store. You need to keep track of the quantity of five different products.
🎯 Goal: Create an array to store the quantities of five products, set a threshold for low stock, find which products are below this threshold, and print their quantities.
📋 What You'll Learn
Create an array called quantities with exactly five integer values: 10, 3, 7, 2, 5
Create an integer variable called lowStockThreshold and set it to 4
Use a for loop with index i to check each quantity in quantities
Create a new array called lowStock to store quantities below the threshold
Print the lowStock array
💡 Why This Matters
🌍 Real World
Stores and warehouses often track product quantities to know when to reorder items.
💼 Career
Understanding arrays and loops is essential for managing collections of data in software development.
Progress0 / 4 steps
1
Create the quantities array
Create an array called quantities with these exact integer values: 10, 3, 7, 2, 5.
Go
Hint

Use Go's array syntax: varName := [size]type{values}

2
Set the low stock threshold
Create an integer variable called lowStockThreshold and set it to 4.
Go
Hint

Use variableName := value to create and set a variable.

3
Find quantities below the threshold
Use a for loop with index i to check each quantity in quantities. Create a slice called lowStock and append quantities less than lowStockThreshold to it.
Go
Hint

Use len(array) to get the array length and append(slice, value) to add items to a slice.

4
Print the low stock quantities
Write a fmt.Println statement to print the lowStock slice.
Go
Hint

Use fmt.Println(lowStock) to display the slice.