Advertisement
Spocoman

Darts Tournament

Oct 6th, 2024 (edited)
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.95 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.     "bufio"
  6.     "os"
  7.     "strconv"
  8. )
  9.  
  10. func main() {
  11.     var startPoints, points, moves int
  12.     fmt.Scanln(&startPoints)
  13.    
  14.     scanner := bufio.NewScanner(os.Stdin)
  15.      
  16.     var command string
  17.      
  18.     for startPoints > 0 {
  19.         moves ++
  20.         scanner.Scan()
  21.         command = scanner.Text()
  22.         if command == "bullseye" {
  23.             break
  24.         }
  25.         scanner.Scan()
  26.         points, _ = strconv.Atoi(scanner.Text())
  27.         if command == "double ring" {
  28.             points *= 2
  29.         } else if command == "triple ring" {
  30.             points *= 3
  31.         }
  32.         startPoints -= points
  33.     }
  34.  
  35.     if startPoints == 0 {
  36.         fmt.Printf("Congratulations! You won the game in %d moves!", moves)
  37.     } else if startPoints < 0 {
  38.         fmt.Printf("Sorry, you lost. Score difference: %d.", startPoints * -1)
  39.     } else {
  40.         fmt.Printf("Congratulations! You won the game with a bullseye in %d moves!", moves)
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement