Link to home
Start Free TrialLog in
Avatar of whiwex
whiwex

asked on

Calculate price of ticket in vb

I'm tracking raffle tickets for local church. This year the price of a ticket is $10 or 3 for $20.
Next year the price maybe $5 or 6 for $22. The user enters the the ticket price's and the prices are stored in a database. As the tickets are sold the user will enter the number of $10 tickets and the number or 3 for $20 packs. The app will then ask them to enter the raffle ticket info i.e. Ticket number, buyer info, seller info. Then this info along with the ticket price will be stored in a database. The problem I am having is trying to calculate the ticket price of the 3 for $20 tickets without hard coding the price. i.e. Ticket 1 price is $6.67 ticket 2 price is $6.67 and ticket 3 price is $6.66 which totals $20. I can hard code this without a problem but I don't want to change this every year. Dose anyone know of a mathematical formula or code that will figure out the cost of each ticket no matter what the number  for dollars is?

Thanks
Avatar of kaufmed
kaufmed
Flag of United States of America image

I would think you would store the price of the ticket (for the current year) in the database as well. You can pull this value once at application start, and then use it in your subsequent calculations; you could also just leave it in the database and do calculations in your query. You could set up a new table that has a price, a ticket/purchase type, and a starting date of when the price went into effect. Then you could simply grab the max date(s) of the column to get the current-year's price; you could also query by year if you are certain the prices won't fluctuate mid-year.
not sure how you input package numbers but could you have two drop down boxes one with the number of package tickets sold and the second the cost of the package.  when read in as an integer the division should be straight forward.
I would create two separate products - a 2013 1-ticket item and a 2013 3-ticket item - for the product year.  Next year create to new products (even if they're priced the same).  

If you normalize the database, product year should be its own table.
Avatar of whiwex
whiwex

ASKER

My problem is one year the tickets are 3 for $20  The next year the tickets are 7 for $15 . How do you calculate the individual ticket price so that when I calculate profit and loss I the individual ticket price totals balance.
user will enter the number of $10 tickets and the number or 3 for $20 packs.


how does the user enter these numbers?  form? command line? prompt?
Avatar of whiwex

ASKER

There is a form that has a textbox for number of tickets and a textbox for Cost.
So the user would enter 3 for number of tickets and 20 for cost. This is stored in a database.
Then when the user wants to enter the tickets the would open a form which has a ticketbox for number of ticket packs sold. The user would enter say one in the number of ticket packs sold and then click a button called add tickets. A form then open asking for the ticket info for ticket 1 then ticket 2 then ticket 3. This info along with the calculated ticket price is stored in a database. The calculated ticket price is what i am having problems with.
Avatar of whiwex

ASKER

I can't just divide the price of the ticket pack by the number of tickets included in the pack because it will always be a few cents off.
"How do you calculate the individual ticket price so that when I calculate profit and loss I the individual ticket price totals balance."
You don't (really) care what the individual ticket price profits are.  What you care about is the profit on item sales.  If an item contains three things - or a dozen things - so what?  If you really need to know the number of tickets sold, you can count the number of 3-ticket items, multiply by three, then add that to the number of 1-ticket items for a total number of tickets.
how about rounding all to the nearest penny eg 6.67 then subtract a penny form one  of them.  Of course you will need s further logic handle other possibilities where the number of tickets is not a factor of the package price.
Avatar of whiwex

ASKER

Rounding to the nearest penny doesn't always work. For example 2 for $20 would yield 2 at 6.67 and one at 6.66 that's ok but what if the next year it's 7 for $15
My advice stands.  Best of luck.
correct

so hence the note that additional logic would be needed

so round to the highest penny
add all together
determine how much it is over the package price
and subtract accordingly

so if 7 for 15 rounded to highest penny is 2.15
7*2.15 =15.05
loop wile subtracting a penny from one ticket at a time until total is 15.00
Avatar of whiwex

ASKER

I was looking for a formula of some type to calculate this. I guess I am just going to use code to do it. Thanks
ASKER CERTIFIED SOLUTION
Avatar of point_pleasant
point_pleasant
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of whiwex

ASKER

What I am going to do is divide the total cost by the number of tickets and round the ticket price to the closest penny. Use this price for all the tickets except for the last ticket. The last ticket price will be the total cost - the sum of all the other tickets. I was hoping to just have a formula to calculate the cost but I guess that isn't possible.
Thanks
For Trying
that will work  just be careful in my extreme case of 99 for 100 the last ticket cost would be a 4 cents for ticket 99
Avatar of whiwex

ASKER

Thanks