-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add for loop to book tickets indefinitely
- Loading branch information
1 parent
f09f8ef
commit 343a846
Showing
1 changed file
with
31 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,53 @@ | ||
package main | ||
|
||
import "fmt" | ||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
// Prints the given string to stdout | ||
func main() { | ||
var conferenceName = "Bheeshma's Conference" | ||
const conferenceTickets = 50 | ||
var remainingTickets uint = 50 | ||
var bookings = []string{} | ||
|
||
fmt.Printf("Welcome to our %v booking application!!\n", conferenceName) | ||
fmt.Printf("We have total of %v tickets and %v are still available for booking\n", conferenceTickets, remainingTickets) | ||
fmt.Println("Get your tickets here to attend") | ||
//var str = "Hello World! This is my first program in go!! Let's Goooo!!" | ||
|
||
var userName string | ||
var tickets uint | ||
for { | ||
var firstName string | ||
var lastName string | ||
var tickets uint | ||
|
||
fmt.Print("Enter your name: ") | ||
fmt.Scan(&userName) | ||
fmt.Print("Enter your first name: \n") | ||
fmt.Scan(&firstName) | ||
|
||
fmt.Print("Enter the number of tickets you want to book: ") | ||
fmt.Scan(&tickets) | ||
fmt.Print("Enter your last name: \n") | ||
fmt.Scan(&lastName) | ||
|
||
fmt.Printf("%v booked %v tickets\n", userName, tickets) | ||
fmt.Print("Enter the number of tickets you want to book: \n") | ||
fmt.Scan(&tickets) | ||
|
||
remainingTickets -= tickets | ||
fmt.Printf("%v booked %v tickets\n", firstName+" "+lastName, tickets) | ||
|
||
fmt.Printf("The remaining number of tickets are: %v\n", remainingTickets) | ||
bookings = append(bookings, firstName+" "+lastName) | ||
|
||
fmt.Println(conferenceName) | ||
remainingTickets -= tickets | ||
var firstNames []string | ||
for _, name := range bookings { | ||
firstNames = append(firstNames, strings.Fields(name)[0]) | ||
} | ||
|
||
fmt.Printf("The remaining number of tickets are: %v\n", remainingTickets) | ||
fmt.Printf("These are the people who made bookings till now: %v\n", firstNames) | ||
|
||
fmt.Printf("Total Number of bookings: %v\n", len(bookings)) | ||
fmt.Printf("The first user to book tickets is: %v\n", bookings[0]) | ||
fmt.Printf("Type of bookings is: %T\n", bookings) | ||
|
||
fmt.Println("Thanks for booking the tickets for", conferenceName, "see you there!") | ||
} | ||
} |