Can anybody implement this algorithm to code in VBA?

l0lcat

New Member
'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.
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
'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
'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
'
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:

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
So, the problem is ???
AND
can you please use code tags ???

Replies
4
Views
2K
Replies
1
Views
560

1,203,396
Messages
6,055,161
Members
444,766
Latest member
bryandaniel5

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back