Advertisement
Spocoman

02. Exam Preparation

Sep 22nd, 2024
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.87 KB | None | 0 0
  1. package main
  2.  
  3. import "fmt"
  4.  
  5. func main() {
  6.     var badGrades int
  7.     fmt.Scanln(&badGrades)
  8.    
  9.     var task string
  10.     fmt.Scanln(&task)
  11.    
  12.     var lastProblem = ""
  13.     var badGradesCounter = 0
  14.     var tasksCount = 0
  15.     var grade float64
  16.     var sumGrades = 0.0
  17.    
  18.     for ; badGradesCounter != badGrades && task != "Enough"; {
  19.         fmt.Scanln(&grade)
  20.         if (grade <= 4) {
  21.             badGradesCounter++
  22.         }
  23.         sumGrades += grade
  24.         lastProblem = task
  25.         tasksCount++
  26.         fmt.Scanln(&task)
  27.     }
  28.  
  29.     if badGradesCounter == badGrades {
  30.         fmt.Printf("You need a break, %d poor grades.\n", badGrades)
  31.     } else {
  32.         fmt.Printf("Average score: %.2f\n", sumGrades / float64(tasksCount))
  33.         fmt.Printf("Number of problems: %d\n", tasksCount)
  34.         fmt.Printf("Last problem: %s\n", lastProblem)
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement