Jump to content

C# Help


Recommended Posts

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."

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 by Chaosmachine420
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...