Ayuda con Struct
Publicado por dario (2 intervenciones) el 23/07/2023 10:40:49
Hola comunidad tengo este codigo, lo que estoy tratando de hacer es almacenar los datos de un struct dentro de un slice pero me aparecen errores, alguien sabe como hacerlo.
Salu2.
Salu2.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package main
import "fmt"
type Caminata struct {
numero int
nombre string
edad int
tiempo int
//categoria string
}
func main() {
var slice1 []Caminata
var i int
var seguir string
for {
fmt.Print("Numero de dorsal: ")
fmt.Scan(&slice1[i].numero)
fmt.Print("Nombre del atleta: ")
fmt.Scan(&slice1[i].nombre)
fmt.Print("Edad: ")
fmt.Scan(&slice1[i].edad)
fmt.Print("Tiempo en segundos: ")
fmt.Scan(&slice1[i].tiempo)
fmt.Println("Desea agregar otro atleta s/n: ")
fmt.Scan(&seguir)
if seguir == "n" {
break
} else {
slice1 = append(slice1, slice1[i])
i++
}
}
}
Valora esta pregunta


0