forked from willmadison/AttendanceLogger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
67 lines (50 loc) · 1.14 KB
/
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
//Import packages
import (
"bufio"
"fmt"
"log"
"os"
)
//Funtion for logging errors
func errorHandler(err error) {
println("Ops, something went wrong:", err)
}
//Function to get attendance
func getStudentInfo() (name, roll, course string) {
fmt.Println("Enter the student name:")
inputReader := bufio.NewReader(os.Stdin)
name, _ = inputReader.ReadString('\n')
fmt.Println("Enter the student roll number:")
inputReader = bufio.NewReader(os.Stdin)
roll, _ = inputReader.ReadString('\n')
fmt.Println("Enter the course:")
inputReader = bufio.NewReader(os.Stdin)
course, _ = inputReader.ReadString('\n')
return name, roll, course
}
//Main
func main() {
name, roll, course := getStudentInfo()
file, err := os.Create("attendance.txt")
if err != nil {
errorHandler(err)
log.Fatalf("%s", err)
}
defer file.Close()
_, err2 := file.WriteString(name)
_, err3 := file.WriteString(roll)
_, err4 := file.WriteString(course)
if err2 != nil {
errorHandler(err2)
log.Fatalf("%s", err2)
}
if err3 != nil {
errorHandler(err3)
log.Fatalf("%s", err3)
}
if err4 != nil {
errorHandler(err4)
log.Fatalf("%s", err4)
}
}