# 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
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
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.
0
Commented:
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.
0
Director, Information SystemsCommented:
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.
0
Author Commented:
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.
0
Commented:
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?
0
Author Commented:
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.
0
Author Commented:
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.
0
Director, Information SystemsCommented:
"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.
0
Commented:
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.
0
Author Commented:
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
0
Director, Information SystemsCommented:
My advice stands.  Best of luck.
0
Commented:
correct

so hence the note that additional logic would be needed

so round to the highest penny
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
0
Author Commented:
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
0
Commented:
its tough to that with out defined parameters.  like 99 tickets for \$100 although not likely would need to be iterated.  but the above logic should get the job done
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Author Commented:
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
0
Commented:
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
0
Author Commented:
Thanks
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Algorithms

From novice to tech pro — start learning today.