Golang Program to read the marks of subjects and display the Grade


Let's enter the marks: 89 56 90 67 99

Sum of the marks is: 89+56+90+67+99 => 401

Avg. = 401/5 = 80.1

The steps are as follows:

  • Define variables for 5 subjects.
  • Enter marks for 5 subjects.
  • Find average of the marks to find grade.
  • Use if else block to print grade.

Example

 Live Demo

package main
import "fmt"
func main(){
   var sub1, sub2, sub3, sub4, sub5 int
   fmt.Println("Enter marks of the five subjects:")
   fmt.Scanf("%d", &sub1)
   fmt.Scanf("%d", &sub2)
   fmt.Scanf("%d", &sub3)
   fmt.Scanf("%d", &sub4)
   fmt.Scanf("%d", &sub5)
   avg:=(sub1+sub2+sub3+sub4+sub5)/5
   if avg>=90{
      print("Grade: A")
   }else if avg>=80 && avg<90{
      print("Grade: B")
   }else if avg>=70 && avg<80{
      print("Grade: C")
   }else if avg>=60 && avg<70{
      print("Grade: D")
   } else{
      print("Grade: F")
   }
}

Output

Enter marks of the five subjects:
89
56
90
67
99
Grade: B

Updated on: 31-Jul-2021

413 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements