Chaosmachine420 Posted October 5, 2012 Share Posted October 5, 2012 I need help taking the directions from my school project and putting them into a list box without having to manually add the percent each time and I cant say for sure if I will need help setting up the math in a simpler way. This is the directions "Given the food charge for the meal in a textbox the program should calculate the tip charges for each value in the range from 10% - 30% and display each as an item in a list box. The program should also display the tax and total bill depending on which item is selected for tip from the listBox." Quote Link to comment Share on other sites More sharing options...
BlueWyvern Posted October 5, 2012 Share Posted October 5, 2012 Ok So if I am understanding this correctly, you need to enter the total, have a list box for the tip %, and based off the tip % selected calculate the subtotal, tax amount, and grand total correct? Quote Link to comment Share on other sites More sharing options...
Chaosmachine420 Posted October 5, 2012 Author Share Posted October 5, 2012 Correct Quote Link to comment Share on other sites More sharing options...
BlueWyvern Posted October 5, 2012 Share Posted October 5, 2012 Well depending on what you have covered in your class, I would add the percents as members of the collection to populate the list, and then either use a case/switch depending on the string value of the box. http://msdn.microsoft.com/en-us/library/06tc147t(v=vs.71).aspx or if you haven't covered that still use the string collection to populate your % values and just use an if / else if statement again based off the selected string value. http://msdn.microsoft.com/en-us/library/5011f09h(v=vs.80).aspx the question is when do you want the tip value calculated? when a tip % is selected? or when you press a total button? That will determine what object and event to trigger your math Best of luck! Quote Link to comment Share on other sites More sharing options...
Chaosmachine420 Posted October 6, 2012 Author Share Posted October 6, 2012 Now I do want to make sure then if I can do my math all on one line or do I have to do them separate lines. My example is this 23(food cost) * .07(tax all the time) = 1.61 + 23 = 24.61 * .15(selected tip) = 3.69 + 24.61 = 28.30 or is there a simpler way to do it. Quote Link to comment Share on other sites More sharing options...
murder_face Posted October 6, 2012 Share Posted October 6, 2012 Can someone explain to me why I wouldn't want to embed something simpler in my code like python to do the math? Quote Link to comment Share on other sites More sharing options...
Chaosmachine420 Posted October 6, 2012 Author Share Posted October 6, 2012 I don't full grasp the case thing and we did go over it just that I do better to see code that relates more to what I want to do. Quote Link to comment Share on other sites More sharing options...
BlueWyvern Posted October 6, 2012 Share Posted October 6, 2012 Now I do want to make sure then if I can do my math all on one line or do I have to do them separate lines. My example is this 23(food cost) * .07(tax all the time) = 1.61 + 23 = 24.61 * .15(selected tip) = 3.69 + 24.61 = 28.30 or is there a simpler way to do it. Actually your math would be more like this (tip should be calcuated outside of tax) For argument's sake (im not saying do this) but i'll use three variables tip = 23(food cost) * .15 (selected tip) tax = 23 (food cost) * .07 (tax) total = 23 (food cost) + tax + tip so your code would be tax = (food_cost) * .07 if listbox.text = "10%" Then tip = (food_cost) * .10 Elseif listbox.text = "15%" Then tip = (food_cost) *.15 End If (Yes I did that in VB to mess with you :P) No freebie code here total = (food_cost) + tip + tax or total = ((food_cost) * tax) + tip the other alternative would be to in your if statement set the tip as it's multiplier value and do your math as total = ((food_cost) * tax) + (tip * (food_cost)) etc etc I never was that great at explaining how to use case effectively ergo why I suggested if all else fails do an if/elseif Quote Link to comment Share on other sites More sharing options...
Chaosmachine420 Posted October 6, 2012 Author Share Posted October 6, 2012 (edited) Now I got it working I have one problem I have a click event that I only want to be able to click once how do I make that happen. I also would like to know if case/switch statements would make the code smaller or longer then what I had to do. Edited October 6, 2012 by Chaosmachine420 Quote Link to comment Share on other sites More sharing options...
pasteywhitecoder Posted October 8, 2012 Share Posted October 8, 2012 Now I got it working I have one problem I have a click event that I only want to be able to click once how do I make that happen. Disable the button in the click event handler. If a control is disabled, it doesn't respond to events (as far as I know). Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.