0
Add to shopping cart - go
https://code.sololearn.com/cbQ7Jy60HCCV/?ref=app I borrowed it and it does not work can someone help me
4 Respuestas
+ 3
You're welcome, Kim Hammar-Milliner.
+ 1
Hello, Kim Hammar-Milliner!
I think my friend can help you:
David Ordás.
He is the best programmer that I know about Go.
+ 1
Thanks
+ 1
package main
import "fmt"
type Cart struct {
prices []float32
}
func (x Cart) show() {
var sum float32 = 0.0
//calculate the sum of all prices in the Cart
for _,v := range x.prices {
sum += v
}
fmt.Println(sum)
}
func main() {
c := Cart{}
var n int
fmt.Scanln(&n)
var x float32
for i:=0; i<n; i++{
fmt.Scanln(&x)
c.prices = append (c.prices,x)
}
// take n inputs and add them to the Cart
//call the show() method of the Cart
c.show()
}