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

12th Dec 2021, 1:44 AM
Kim Hammar-Milliner
Kim Hammar-Milliner - avatar
4 Respuestas
+ 3
You're welcome, Kim Hammar-Milliner.
13th Dec 2021, 1:49 AM
CGO!
CGO! - avatar
+ 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.
12th Dec 2021, 4:45 PM
CGO!
CGO! - avatar
+ 1
Thanks
13th Dec 2021, 1:45 AM
Kim Hammar-Milliner
Kim Hammar-Milliner - avatar
+ 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() }
17th Dec 2021, 3:19 AM
Raed
Raed - avatar