'This function is the starting point of the program.
'It welcomes the user, and asks which package they want (after displaying a menu of options).
'Once they enter a valid package it uses getQuantity to get the number of each type of ticket
'(adult, child and concession) and then finds the total cost using calcTotalCost.
'If the total cost is over 100 then it uses getDiscount to see if they get a 20% discount,
'and tells the user if they get it. Finally it prints the total cost and ends.
'It welcomes the user, and asks which package they want (after displaying a menu of options).
'Once they enter a valid package it uses getQuantity to get the number of each type of ticket
'(adult, child and concession) and then finds the total cost using calcTotalCost.
'If the total cost is over 100 then it uses getDiscount to see if they get a 20% discount,
'and tells the user if they get it. Finally it prints the total cost and ends.
Code:
Sub main()
'display welcome to user and ask which package they want
'get package from user, convert it to uppercase
'while package is not 'B', or 'P', or 'E'
' Print Error; Message
' get package from user, convert it to uppercase
'adultTickets = call getQuantity("How many adult tickets? ")
'childTickets = call getQuantity("How many child tickets? ")
'concTickets = call getQuantity("How many concession tickets? ")
'ticketCost = call calcTotalCost(package, adultTickets, childTickets, concTickets)
'if ticketCost is > 100 then:
'discounted = call getDiscount()
'If discounted = True Then:
' ticketCost = ticketCost * 0.8
' display "You received a 20% discount"
'display ticketCost
End Sub
'This function will take the type of package, and the number of each type of ticket
'(adult, child and concession) as inputs and will calculate the total cost of all
'tickets for the appropriate package. This value will then be returned.
Function calcTotalCost(packageCode, numAdultTickets, numChildTickets, numConcTickets) As Integer
'adultCost = numAdultTickets * ADULT_TICKET_PRICE
'childCost = numChildTickets * CHILD_TICKET_PRICE
'concCost = numConcTickets * CONC_TICKET_PRICE
'totalCost = adultCost + childCost + concCost
'
'if packageCode = 'P' then:
' totalCost = totalCost * PREMIUM_FACTOR
'otherwise if packageCode = 'E' then:
' totalCost = totalCost * EXTRAVAGANT_FACTOR
'
'return totalCost
End Function
'This function generates a random number, and if it is equal to the 'lucky number'
'then it returns 'True', otherwise it returns 'False'
Function getDiscount()
'generate randomNum between 1-10 inclusive
'If randomNum = LUCKYNUM Then:
'discount = True
'otherwise:
'discount = False
'return discount
End Function
'This function will take a prompt as input, display it to the user and get a value in response.
'If the user enters a value below zero then an error is displayed, and they will be asked again
'until they enter a value of 0 or more. This value is then returned from the function
Function getQuantity(prompt):
'display prompt
'get value from user
'while value is less than zero:
'Print an Error
'display prompt
'get value
'Return 'value'
End Function
Last edited by a moderator: