0
Can you explain the last part of this question?
The match results are stored in an array called results. Each match has one of the following results: "w" - won "l" - lost "d" - draw A win adds three points, a draw adds one point, and a lost match does not add any points. Your program needs to take the last match result as input and append it to the results array. After that, calculate and output the total points the team gained from the results. Note: I will post my program in the comments section.
6 Answers
+ 3
I don't know anything about go or this code but from what i understand , it is asking to take an input and append it to existing array . Later sum all of the array based on w , l or d.
+ 1
Uppili OMS
You didn't take that input num which should be append in array so do this:
var num string
fmt.Scanln(&num)
total := 0
results = append(results, num)
Rest code is ok.
0
package main
import "fmt"
func main() {
results := []string{"w", "l", "w", "d", "w", "l", "l", "l", "d", "d", "w", "l", "w", "d"}
total := 0
results = append(results, results[num])
for _,val:= range results {
switch val {
case "w": total += 3; break;
case "l": break;
default: total += 1; break;
}
}
fmt.Println(total)
}
This is my code.
0
They had asked to take an User Input and append to the array ?
0
Uppili OMS right .You can try it and if that doesn't works then i am sorry !
0
It did indeed work bro, Thanks đ