C# Calculation not correct -
when run code, doesn't calculate , doesn't show calculations. wondering if variables or else wrong or maybe in wrong place.
using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.threading.tasks; using system.windows.forms; namespace question_3_retail_price_calculator { public partial class form1 : form { public form1() { initializecomponent(); } private void button1_click(object sender, eventargs e) { decimal costprice = 0; decimal markupratea = 0.19m; decimal markuprateb = 0.14m; decimal markupratec = 0.12m; decimal markuprate = 0m; decimal markuptotal = 0; decimal totalcost = 0; // add items listbox 1 listbox1.items.add("markup rate ="); listbox1.items.add("markup total ="); listbox1.items.add("total cost ="); try { // read cost price user costprice = decimal.parse(textbox1.text); } catch (system.exception excep ) { messagebox.show(excep.message); } if (costprice <= 50) { // calculate value of product costprice = (costprice / 100) * markupratea; } else if (costprice >= 50 && costprice < 100) { // calculate value of product costprice = (costprice / 100) * markuprateb; } else if (costprice < 100) { // calculate value of product costprice = (costprice / 100) * markupratec; } else if (markuprate == markuptotal) { // calculate total monetary amount markuptotal = costprice * markuprate; } else { // calculate total cost of product totalcost = costprice + markuptotal; } // output total cost messagebox.show("total cost is: €" + totalcost); } } }
need figuring out! in advance!
you're setting total cost in last else condition executed if other if-else conditions not executed. why code isn't working expect.
even if enter value >100, result never assigned totalcost. because execution enters part of code
else if (markuprate == markuptotal) { // calculate total monetary amount markuptotal = costprice * markuprate; }
and jumps directly message.show(..)
line.
Comments
Post a Comment