Advertisement
Spocoman

04. Grades

Sep 21st, 2024
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.93 KB | None | 0 0
  1. package main
  2.  
  3. import "fmt"
  4.  
  5. func main() {
  6.     var students int
  7.     fmt.Scanln(&students)
  8.  
  9.     var grade3 = 0.0
  10.     var grade4 = 0.0
  11.     var grade5 = 0.0
  12.     var grade6 = 0.0
  13.     var gradeSum = 0.0
  14.    
  15.     var grade float64
  16.  
  17.     for i := 0; i < students; i++ {
  18.         fmt.Scanln(&grade)
  19.         if grade >= 5 {
  20.             grade6++
  21.         } else if grade >= 4 {
  22.             grade5++
  23.         } else if grade >= 3 {
  24.             grade4++
  25.         } else if grade >= 2 {
  26.             grade3++
  27.         }
  28.         gradeSum += grade
  29.     }
  30.  
  31.     fmt.Printf("Top students: %.2f%%\n", grade6 / float64(students) * 100.0)
  32.     fmt.Printf("Between 4.00 and 4.99: %.2f%%\n", grade5 / float64(students) * 100.0)
  33.     fmt.Printf("Between 3.00 and 3.99: %.2f%%\n", grade4 / float64(students) * 100.0)
  34.     fmt.Printf("Fail: %.2f%%\n", grade3 / float64(students) * 100.0)
  35.     fmt.Printf("Average: %.2f\n", gradeSum / float64(students))
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement