Skip to content

Commit

Permalink
Added example of an array and a slice
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasWhittington committed Sep 14, 2024
1 parent e91520a commit 4beb7b6
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ func main() {
var conferenceName = "Go conference"
const conferenceTickets uint = 50
var remainingTickets uint = conferenceTickets
var bookingsArray [50]string
var bookingsSlice []string

fmt.Printf("conferenceTickets is %T, remainingTickets is %T, conferenceName is %T\n", conferenceTickets, remainingTickets, conferenceName)

Expand All @@ -28,6 +30,18 @@ func main() {
fmt.Scan(&userTickets)

remainingTickets -= userTickets
bookingsArray[0] = firstName + " " + lastName
bookingsSlice = append(bookingsSlice, firstName+" "+lastName)

fmt.Printf("The whole array: %v\n", bookingsArray)
fmt.Printf("the first value: %v\n", bookingsArray[0])
fmt.Printf("Array type: %T\n", bookingsArray)
fmt.Printf("Array length: %v\n", len(bookingsArray))

fmt.Printf("The whole slice: %v\n", bookingsSlice)
fmt.Printf("the first value: %v\n", bookingsSlice[0])
fmt.Printf("Slice type: %T\n", bookingsSlice)
fmt.Printf("Slice length: %v\n", len(bookingsSlice))

fmt.Printf("Thankyou %v %v for booking %v tickets. You will recieve a confirmation email at %v\n", firstName, lastName, userTickets, email)
fmt.Printf("%v tickets remaining for %v\n", remainingTickets, conferenceName)
Expand Down

0 comments on commit 4beb7b6

Please sign in to comment.