Compute a student's average score across three tests using integer division so the result is a whole number.
You start with:
var test1 int = 85
var test2 int = 92
var test3 int = 78
Build:
Average: 85
Rules:
- Compute the integer average of
test1,test2, andtest3using integer division (intdivided byintalready drops the remainder). - Print
"Average: "followed by the average; usestrconv.Itoa(...)to join an integer to a string.
Go's
int / int truncates, so (test1 + test2 + test3) / 3 already gives an integer.
var test1 int = 85
var test2 int = 92
var test3 int = 78
var average int = (test1 + test2 + test3) / 3
fmt.Println("Average: " + strconv.Itoa(average))
Free plan: 30 tutor messages. Premium is unlimited.
Saved
Ctrl + Enter to check
