0
0
Goprogramming~15 mins

Array declaration in Go - Mini Project: Build & Apply

Choose your learning style9 modes available
Array declaration
📖 Scenario: You are organizing a small event and want to keep track of the number of guests arriving each day over a week.
🎯 Goal: Create an array to store the number of guests for each day of the week.
📋 What You'll Learn
Create an array with exactly 7 integers representing guests per day
Use the array to store the exact values given
Print the array to show the guest counts
💡 Why This Matters
🌍 Real World
Arrays are useful to store fixed sets of related data, like daily counts or measurements.
💼 Career
Understanding arrays and loops is fundamental for programming tasks in any software development job.
Progress0 / 4 steps
1
Create an array with guest counts
Create an array called guests of type [7]int with these exact values: 12, 15, 10, 20, 18, 25, 30.
Go
Hint

Use the syntax varName := [size]type{values} to declare and initialize an array.

2
Add a variable for total guests
Create an integer variable called totalGuests and set it to 0.
Go
Hint

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

3
Calculate total guests using a loop
Use a for loop with the variable i from 0 to 6 to add each day's guests from guests[i] to totalGuests.
Go
Hint

Use a for loop with index i to access array elements by guests[i].

4
Print the total number of guests
Write a fmt.Println statement to print the text Total guests: followed by the value of totalGuests.
Go
Hint

Use fmt.Println("Total guests:", totalGuests) to print the message and number.