none
Creating a vending machine using VBA coding RRS feed

  • Question

  •   Please help                                                                                                                                                            Task: Given products in a vending machine (Table 1) and their respective prices (Table 2), develop VBA code that would undertake the following tasks after the customer clicks the ‘purchase a product’ button: a. To the customer: i. Receive the customer’s selected product code. ii. Confirm and display the customer’s selected product and product price. iii. Receive the customer’s money which may be input in one or more of the prescribed denominations (Table 3). iv. Flag any input error. [i + ii + iii + iv = 3 marks] v. Flag any processing error. vi. Determine (and inform the customer) if the selected product is unavailable. If unavailable, another product may be selected. vii. Determine (and inform the customer) if change for the selected product is unavailable. If unavailable, another product may be selected. 2 viii. Prevent (and inform) the customer from receiving a product if the total of the monies input by the customer is less than the selected product price. ix. Dispense the selected product without change if the total of the monies input by the customer is equal to the product price or dispense the product with the correct change in specified denominations should the total of the monies input by the customer be more than the product price. [v + vi + vii + viii+ ix = 6 marks] b. To the owner of the vending machine: x. Calculate and display the change in the different monetary denominations remaining in the machine. xi. Calculate and display the quantity of each product remaining in the machine. [x + xi = 3 marks] Additional information:  Hardcopy algorithm. [3 marks]  Bonus marks (e.g. efficiency of VBA code, use of comments, user-friendliness….). [2 marks]  The vending machine products and monies for change are refreshed at the same time weekly.  There are 10 of each product within the vending machine immediately after refreshing. Table 1. Products and product codes 1 2 3 4 1 Simba cheese and onion Product code: 11 Simba Nik Naks Product code: 12 Fritos corn chips Product code: 13 Lays Product code: 14 2 Doritos Product code: 21 Eet sum mor Product code: 22 Diddle Daddle Product code: 23 Oreo Product code: 24 3 Snickers Product code: 31 Bar One Product code: 32 Kit Kat Product code: 33 Lunch Bar Product code: 34 4 Coca-Cola Product code: 41 BonAqua Product code: 42 Fanta Grape Product code: 43 Twist Product code: 44 Table 2. Prices 1 2 3 4 1 R 10.00 R 10.00 R 10.00 R 10.00 2 R 10.00 R 5.00 R 5.00 R 10.00 3 R 10.00 R 10.00 R 10.00 R 10.00 4 R 15.00 R 10.00 R 15.00 R 15.00  The vending machine will only accept the following denominations: R20, R10, R5, R2 and R1  Monies accepted for purchases will not be added to the monies allocated for change.  Immediately after refreshing, the vending machine has the following quantities of each monetary denomination for change (Table 3). Table 3. Change in the vending machine immediately after refreshing Denomination R 10.00 R 5.00 R 2.00 R 1.00 Total number 50 50 75 100
    Friday, October 14, 2016 4:32 PM

All replies

  •   Please help                                                                                                                                                            Task: Given products in a vending machine (Table 1) and their respective prices (Table 2), develop VBA code that would undertake the following tasks after the customer clicks the ‘purchase a product’ button: a. To the customer: i. Receive the customer’s selected product code. ii. Confirm and display the customer’s selected product and product price. iii. Receive the customer’s money which may be input in one or more of the prescribed denominations (Table 3). iv. Flag any input error. [i + ii + iii + iv = 3 marks] v. Flag any processing error. vi. Determine (and inform the customer) if the selected product is unavailable. If unavailable, another product may be selected. vii. Determine (and inform the customer) if change for the selected product is unavailable. If unavailable, another product may be selected. 2 viii. Prevent (and inform) the customer from receiving a product if the total of the monies input by the customer is less than the selected product price. ix. Dispense the selected product without change if the total of the monies input by the customer is equal to the product price or dispense the product with the correct change in specified denominations should the total of the monies input by the customer be more than the product price. [v + vi + vii + viii+ ix = 6 marks] b. To the owner of the vending machine: x. Calculate and display the change in the different monetary denominations remaining in the machine. xi. Calculate and display the quantity of each product remaining in the machine. [x + xi = 3 marks] Additional information:  Hardcopy algorithm. [3 marks]  Bonus marks (e.g. efficiency of VBA code, use of comments, user-friendliness….). [2 marks]  The vending machine products and monies for change are refreshed at the same time weekly.  There are 10 of each product within the vending machine immediately after refreshing. Table 1. Products and product codes 1 2 3 4 1 Simba cheese and onion Product code: 11 Simba Nik Naks Product code: 12 Fritos corn chips Product code: 13 Lays Product code: 14 2 Doritos Product code: 21 Eet sum mor Product code: 22 Diddle Daddle Product code: 23 Oreo Product code: 24 3 Snickers Product code: 31 Bar One Product code: 32 Kit Kat Product code: 33 Lunch Bar Product code: 34 4 Coca-Cola Product code: 41 BonAqua Product code: 42 Fanta Grape Product code: 43 Twist Product code: 44 Table 2. Prices 1 2 3 4 1 R 10.00 R 10.00 R 10.00 R 10.00 2 R 10.00 R 5.00 R 5.00 R 10.00 3 R 10.00 R 10.00 R 10.00 R 10.00 4 R 15.00 R 10.00 R 15.00 R 15.00  The vending machine will only accept the following denominations: R20, R10, R5, R2 and R1  Monies accepted for purchases will not be added to the monies allocated for change.  Immediately after refreshing, the vending machine has the following quantities of each monetary denomination for change (Table 3). Table 3. Change in the vending machine immediately after refreshing Denomination R 10.00 R 5.00 R 2.00 R 1.00 Total number 50 50 75 100

    There is a different Forum for VBA - Visual Basic for Applications (VBA).

    Also if this is homework, schoolwork, etc then it doesn't appear as if you have bothered doing anything yet and are instead asking others either how to do something you should be learning how to do or you want somebody else to do it for you. I would suggest you get help from your instructor and/or other students that have the same "task".


    La vida loca

    Friday, October 14, 2016 4:46 PM
  • HL,

    If this is VB (not VBA) then I'll help but it'll be abundantly obvious that you didn't write the code.

    Let me know your thoughts and we'll go from there.

    "Everybody in this country should learn how to program a computer... because it teaches you how to think." (Steve Jobs)

    Friday, October 14, 2016 5:47 PM