Chapter 3 - Functions
Exercise 1: fmt.Printf
The program below should produce a table with student names, their scores on three tests, and the average of those scores.
Write a scoreSummary
function that accepts a string
parameter with the student name, followed by three float64
parameters with the test scores. Calculate the average of the scores by adding them all together and dividing the result by three. Then call fmt.Printf
to print a table row with the following columns:
- The student name string, with a width of 10 characters.
- The first test score, with a with of 8 characters, 2 of them decimal places.
- The second test score, with a with of 8 characters, 2 of them decimal places.
- The third test score, with a with of 8 characters, 2 of them decimal places.
- The average of the scores, with a with of 8 characters, 2 of them decimal places.
Solution
Output:
Name | Score 1 | Score 2 | Score 3 | Average
------------------------------------------------------
Jermaine | 95.40 | 82.30 | 74.60 | 84.10
Jessie | 79.30 | 99.10 | 82.50 | 86.97
Lamar | 82.20 | 95.40 | 77.60 | 85.07