|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "encoding/csv" |
| 5 | + "flag" |
| 6 | + "fmt" |
| 7 | + "io/ioutil" |
| 8 | + "log" |
| 9 | + "path/filepath" |
| 10 | + "strings" |
| 11 | + "time" |
| 12 | +) |
| 13 | + |
| 14 | +func startTime(timer time.Timer, duration time.Duration) { |
| 15 | + <-timer.C |
| 16 | + fmt.Println(duration, "doldu") |
| 17 | +} |
| 18 | + |
| 19 | +func main() { |
| 20 | + filename := flag.String("file", "problems.csv", "Questions file") |
| 21 | + timelimit := flag.Int("time", 30, "Time limit of quiz in seconds") |
| 22 | + flag.Parse() |
| 23 | + |
| 24 | + filePath, pathErr := filepath.Abs(*filename) |
| 25 | + if pathErr != nil { |
| 26 | + log.Fatal("file not found. check if it exists again.") |
| 27 | + } |
| 28 | + |
| 29 | + remainTime := time.Duration(*timelimit) * time.Second |
| 30 | + fmt.Println("Press return to start time (", remainTime, ")") |
| 31 | + fmt.Scanln() //and time starts |
| 32 | + |
| 33 | + timer := time.NewTimer(remainTime) |
| 34 | + go startTime(*timer, remainTime) |
| 35 | + |
| 36 | + csvF, csvErr := ioutil.ReadFile(filePath) |
| 37 | + if csvErr != nil { |
| 38 | + log.Fatal("error reading file: " + csvErr.Error()) |
| 39 | + } |
| 40 | + |
| 41 | + probs, probErr := csv.NewReader(strings.NewReader(string(csvF))).ReadAll() |
| 42 | + if probErr != nil { |
| 43 | + log.Fatal("error on CSV format: " + probErr.Error()) |
| 44 | + } |
| 45 | + |
| 46 | + var answer string |
| 47 | + var trues, total int |
| 48 | + |
| 49 | + for i, soru := range probs { |
| 50 | + fmt.Printf("%d. soru: %s = ", i+1, soru[0]) |
| 51 | + fmt.Scan(&answer) |
| 52 | + if answer == soru[1] { |
| 53 | + trues++ |
| 54 | + } |
| 55 | + total++ |
| 56 | + } |
| 57 | + |
| 58 | + fmt.Printf("True answers: %d\n", trues) |
| 59 | + fmt.Printf("Total questions: %d\n", total) |
| 60 | +} |
0 commit comments