vb.net - visual basic function discounts 1 and 2 -
i'm working on code class , i'm having trouble function part.
i have this. need function accepts subtotal , calculates discount using subtotal > 200 discount of 1% subtotal > 100 discount of .5%
i struggling functions , need if point me in right direction please , thank you.
public class form1 const consthandwashprice decimal = 10d const constinteriorshampooprice decimal = 30d const constcarwaxprice decimal = 25d const constengineshampooprice decimal = 15d const constinteriorvacuumprice decimal = 16d const constoilchangeprice decimal = 34.95d const construstproofingprice decimal = 89.99d const consttirerotationprice decimal = 15d const constalignmentprice decimal = 63.88d const constfrontbrakesprice decimal = 75.66d const constrearbrakesprice decimal = 78.9d dim discount decimal dim total decimal dim subtotal decimal dim customername integer dim address integer private sub cbservices_selectedindexchanged(sender object, e eventargs) handles cbservices.selectedindexchanged dim index integer dim price decimal dim msg string index = cbservices.selectedindex if index = 0 price = consthandwashprice total += consthandwashprice subtotal += consthandwashprice end if if index = 1 price = constinteriorshampooprice total += constinteriorshampooprice subtotal += constinteriorshampooprice end if if index = 2 price = constcarwaxprice total += constcarwaxprice subtotal += constcarwaxprice end if if index = 3 price = constengineshampooprice total += constengineshampooprice subtotal += constengineshampooprice end if if index = 4 price = constinteriorvacuumprice total += constinteriorvacuumprice subtotal += constinteriorvacuumprice end if if index = 5 price = constoilchangeprice total += constoilchangeprice subtotal += constoilchangeprice end if if index = 6 price = construstproofingprice total += construstproofingprice subtotal += construstproofingprice end if if index = 7 price = consttirerotationprice total += consttirerotationprice subtotal += consttirerotationprice end if if index = 8 price = constalignmentprice total += constalignmentprice subtotal += constalignmentprice end if if index = 9 price = constfrontbrakesprice total += constfrontbrakesprice subtotal += constfrontbrakesprice end if if index = 10 price = constrearbrakesprice total += constrearbrakesprice subtotal += constrearbrakesprice end if msg = cbservices.items.item(index) & vbtab & formatcurrency(price) lbss.items.add(msg) lblsubtotal.text = formatcurrency(subtotal) end sub private sub cleartoolstripmenuitem_click(sender object, e eventargs) handles cleartoolstripmenuitem.click lbss.items.clear() lbprint.items.clear() lblsubtotal.text = "" txtad.text = "" txtcn.text = "" subtotal = 0 end sub private sub exittoolstripmenuitem_click(sender object, e eventargs) handles exittoolstripmenuitem.click if msgbox("are sure want exit?", msgboxstyle.okcancel) = msgboxresult.ok application.exit() end if end sub private sub printtoolstripmenuitem_click(sender object, e eventargs) handles printtoolstripmenuitem.click dim index integer lbprint.items.add("sam's customer care") lbprint.items.add(environment.newline) lbprint.items.add("bill to:" & txtcn.text.tostring & vbtab & txtad.text.tostring) lbprint.items.add(environment.newline) while index < lbss.items.count lbprint.items.add(lbss.items(index)) index += 1 loop lbprint.items.add("--------------------------------------------------------------------------") lbprint.items.add("subtotal: " & formatcurrency(subtotal)) lbprint.items.add("discount: " & formatcurrency(discount)) end sub
are looking function given total makes discount? this?
private function getdiscountedtotal(subtotal decimal) decimal return if(subtotal > 100, if(subtotal > 200, subtotal - (subtotal * 0.1d), subtotal - (subtotal * 0.5d)), subtotal) end function
example of usage
subtotal = getdiscountedtotal(subtotal)
Comments
Post a Comment