Cruz Castillo

Generation

generate functionFri, 05 May 2023

Bot program to count the products bought in the supermarket, with total sum.

package main import ( "fmt" "strconv" ) func main() { var userInput string sum := 0 for { fmt.Print("Enter a number or 'X' to quit: ") fmt.Scan(&userInput) if userInput == "X" { fmt.Printf("Sum: %d", sum) break } value, err := strconv.Atoi(userInput) if err != nil { fmt.Println("Bad value!") continue } sum += value } }

Want to kickstart your project?Use the new AI Studio to create your code