0
Can somebody help me with Match Results the course is go
My code package main import "fmt" func main() { results := []string{"w", "l", "w", "d", "w", "l", "l", "l", "d", "d", "w", "l", "w", "d"} int a,b; int w,l,d; if(a>b){ fmt.Println("w") } else if(a<b){ fmt.Println("l") } else{ fmt.Println("d") } }
10 Antworten
+ 4
package main
import "fmt"
func main() {
results := []string{"w", "l", "w", "d", "w", "l", "l", "l", "d", "d", "w", "l", "w", "d"}
score := 0
var lastres string
fmt.Scanln(&lastres)
results = append(results, lastres)
for _, v := range results {
switch v {
case "w":
score += 3
case "d":
score += 1
}
}
fmt.Println(score)
}
0
Try to explain well
0
Give answer
0
You are making a program to analyze sport match results and calculate the points of the given team.
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.
0
here is the answer to that question:-
package main
import (
"fmt"
)
func main() {
results := []string{"w", "l", "w", "d", "w", "l", "l", "l", "d", "d", "w", "l", "w", "d"}
var a,b int;
var first string;
a = 0;
fmt.Scanln(&first) ;
results = append(results, first)
for b =0; b<len(results); b++ {
dataResult := results[b];
if (dataResult == "w"){
a= 3 +a;
}else if(dataResult =="d"){
a= 1 +a;
}
}
fmt.Println(a)
}
0
package main
import "fmt"
func main() {
results := []string{"w", "l", "w", "d", "w", "l", "l", "l", "d", "d", "w", "l", "w", "d"}
score := 0
var lastres string
fmt.Scanln(&lastres)
results = append(results, lastres)
for _, v := range results {
switch v {
case "w":
score += 3
case "d":
score += 1
}
}
fmt.Println(score)
}package main
import "fmt"
func main() {
results := []string{"w", "l", "w", "d", "w", "l", "l", "l", "d", "d", "w", "l", "w", "d"}
score := 0
var lastres string
fmt.Scanln(&lastres)
results = append(results, lastres)
for _, v := range results {
switch v {
case "w":
score += 3
case "d":
score += 1
}
}
fmt.Println(score)
}
0
package main
import "fmt"
/*
win = 3
draw = 1
lost = 0
*/
func main() {
results := []string{"w", "l", "w", "d", "w", "l", "l", "l", "d", "d", "w", "l", "w", "d"}
score := 0
var input string
fmt.Scanln(&input)
results = append(results, input)
for _, v := range results {
if v == "w" {
score += 3
}
if v == "d" {
score += 1
}
}
fmt.Println(score)
}
0
package main
import "fmt"
func main() {
var (
lastRes []rune
total uint8
)
results := []rune{'w', 'l', 'w', 'd', 'w', 'l', 'l', 'l', 'd', 'd', 'w', 'l', 'w', 'd'}
var tmp string
fmt.Scanln(&tmp)
lastRes = []rune(tmp)
results = append(results, lastRes...)
for _, v := range results {
switch {
case v == 119:
total += 3
case v == 100:
total += 1
}
}
fmt.Println(total)
}
0
package main
import "fmt"
func calc(s... string) {
var scores = map[string]int{"w":3, "d": 1, "l": 0}
var sum int
for _, i := range s {
sum += scores[i]
}
fmt.Println(sum)
}
func main() {
results := []string{"w", "l", "w", "d", "w", "l", "l", "l", "d", "d", "w", "l", "w", "d"}
var l string
fmt.Scanln(&l)
results = append(results, l)
calc(results...)
}
- 2
Explain the question better thats what i mean