我正在尝试学习 Golang,因为我正在与 Nana 一起使用 Techworld 在 Youtube 上做一个教程,并学习使用函数对逻辑进行分组,它显示了一个之前不存在的错误,并且它没有在视频中显示给她。
bookTicket(remainingTickets, userTickets, bookings, firstName, lastName, email, conferenceName)
以上是对以下函数的调用:
func bookTicket(remainingTickets uint, userTickets uint, bookings []string, firstName string, lastName string, email string, conferenceName string) {
remainingTickets = remainingTickets - userTickets
bookings = append(bookings, firstName+" "+lastName)
它说“这个预订价值从未使用过(SA4006)”
所以,这里是整个代码:
https://go.dev/play/p/GFMR7f64li1
package main
import (
"fmt"
"strings"
)
func main() {
conferenceName := "Go Conference"
const conferenceTickets int = 50
var remainingTickets uint = 50
bookings := []string{}
greetUsers(conferenceName, conferenceTickets, remainingTickets)
for {
firstName, lastName, email, userTickets := getUserInput()
isValidName, isValidEmail, isValidTicketNumber := validateUserInput(firstName, lastName, email, userTickets, remainingTickets)
if isValidName && isValidEmail && isValidTicketNumber {
bookTicket(remainingTickets, userTickets, bookings, firstName, lastName, email, conferenceName)
firstNames := getFirstNames(bookings)
fmt.Printf("The first name of our bookings are: %v\n", firstNames)
if remainingTickets == 0 {
// sair do loop/programa
fmt.Println("Our conference is booked out. Come back next year.")
break
}
} else {
if !isValidName {
fmt.Println("First name or last name too short.")
}
if !isValidEmail {
fmt.Println("E-mail doesn't contain @ sign.")
}
if !isValidTicketNumber {
fmt.Println("Number of tickets entered is invalid.")
}
}
}
}
动漫人物
收到一只叮咚
相关分类