-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
148 lines (94 loc) · 2.97 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package main
import (
"booking-app/helper"
"fmt"
"time"
)
var ConferenceName = "Go Conference"
const conferencetickets = 50
var remainingtickets uint = 50
var bookings = make([]userdata, 0)
type userdata struct {
firstname string
lastname string
email string
tickets uint
}
func main() {
greetusers()
for {
firstname, lastname, email, tickets := getuserinput()
isvalidname, isvalidemail, isvalidtickets := helper.Validateuserinput(firstname, lastname, email, tickets, remainingtickets)
if isvalidname && isvalidemail && isvalidtickets {
bookticket(tickets, firstname, lastname, email)
go sendticket(tickets, firstname, lastname, email)
firstNames := getfirstnames()
fmt.Printf("The first names of bookings are : %v\n", firstNames)
if remainingtickets == 0 {
fmt.Println("All tickets Sold")
break
}
} else {
if !isvalidname {
fmt.Println("First name or Last name you entered is too short")
}
if !isvalidemail {
fmt.Println("Your email doesn't contain @ sign")
}
if !isvalidtickets {
fmt.Println("Number of tickets you entered is invalid")
}
}
}
}
func Validateuserinput(firstname, lastname, email string, tickets, remainingtickets uint) {
panic("unimplemented")
}
func greetusers() {
fmt.Printf("Welcome to %v booking application\n", ConferenceName)
fmt.Printf("We have total of %v tickets and %v are still available\n", conferencetickets, remainingtickets)
fmt.Println("Get your tickets here to attend")
}
func getfirstnames() []string {
firstNames := []string{}
for _, booking := range bookings {
//var names = strings.Fields(booking)
firstNames = append(firstNames, booking.firstname)
}
return firstNames
}
func getuserinput() (string, string, string, uint) {
var firstname string
var lastname string
var email string
var tickets uint
fmt.Println("Enter first name : ")
fmt.Scan(&firstname)
fmt.Println("Enter last name : ")
fmt.Scan(&lastname)
fmt.Println("Enter email : ")
fmt.Scan(&email)
fmt.Println("Enter number of tickets : ")
fmt.Scan(&tickets)
return firstname, lastname, email, tickets
}
func bookticket(tickets uint, firstname string, lastname string, email string) {
remainingtickets = remainingtickets - tickets
var userdata = userdata{
firstname: firstname,
lastname: lastname,
email: email,
tickets: tickets,
}
bookings = append(bookings, userdata)
fmt.Printf("List of Bookings is %v\n", bookings)
fmt.Printf("Thank you %v %v for booking %v tickets. You will recieve a confirmation at %v\n", firstname, lastname, tickets, email)
fmt.Printf("Remaining tickets : %v\n", remainingtickets)
}
func sendticket(tickets uint, firstname string, lastname string, email string) {
time.Sleep(10 * time.Second)
var ticket = fmt.Sprintf("%v tickets for %v %v", tickets, firstname, lastname)
fmt.Println("######################")
fmt.Printf("Sending ticket:\n %v \n to email address %v\n", ticket, email)
fmt.Println("#######################")
}