-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
46 lines (40 loc) · 971 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package main
import (
"bufio"
"flag"
"fmt"
"log"
"os"
"strings"
"github.com/kennykarnama/arithmetic_quiz_go/quiz"
)
func main() {
pathFile := flag.String("file", "example.csv", "Path to csv file")
flag.Parse()
quiz, err := quiz.NewQuizFromCsvFile(*pathFile)
if err != nil {
log.Fatal(err)
}
idx := 0
correctAnswer := 0
totalQuestion := len(quiz.Questions)
for idx < len(quiz.Questions) {
q := quiz.Pick(idx)
reader := bufio.NewReader(os.Stdin)
fmt.Printf("%s\n", q.QuestionDescription)
text, _ := reader.ReadString('\n')
text = strings.TrimRight(text, "\n")
text = strings.TrimSpace(text)
keyAnswer := strings.TrimRight(q.KeyAnswer, "\n")
if text == keyAnswer {
correctAnswer++
} else {
fmt.Printf("%s %s \n", text, keyAnswer)
}
idx++
}
fmt.Printf("****** RESULT *****\n")
fmt.Printf("Correct Answer %d\n", correctAnswer)
fmt.Printf("Total questions %d\n", totalQuestion)
fmt.Printf("****** END RESULT *****\n")
}