Skip to content

Commit

Permalink
Add for loop to book tickets indefinitely
Browse files Browse the repository at this point in the history
  • Loading branch information
BheeshmasenaReddy committed Jul 8, 2023
1 parent f09f8ef commit 343a846
Showing 1 changed file with 31 additions and 11 deletions.
42 changes: 31 additions & 11 deletions main.go
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!")
}
}

0 comments on commit 343a846

Please sign in to comment.