Tuesday 15 February 2011

Trouble with calling methods in c# -



Trouble with calling methods in c# -

i working on intro level c# calss , having incredibly hard time figuring out methods. book not seem clear in instances. current assignment trying create programme calculates cost of hospital stay. need have 3 different methods program. sense have methods @ to the lowest degree created correctly unsure how create programme output things methods during button click event. here have far(i have tried 1000000 different things in calcbtn_click method , firmly confused).

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 windowsformsapplication6 { public partial class form1 : form { public form1() { initializecomponent(); } private int calcstaycharges() { int lengthofstay; lengthofstay = int.parse(daystayed.text); int totalstaycharges = (350 * lengthofstay); homecoming totalstaycharges; } private double calcmisccharges() { double medcharges; medcharges = double.parse(medcharge.text); double surgcharges; surgcharges = double.parse(surgicalcharge.text); double labfees; labfees = double.parse(labfee.text); double rehabcharges; rehabcharges = double.parse(rehabcharge.text); double misccharge = (medcharges + surgcharges + labfees + rehabcharges); homecoming misccharge; } public double calctotalcharges() { double misccharges = calcmisccharges(); int staycharges = calcstaycharges(); double totalcharges = misccharges + staycharges; homecoming totalcharges; } private void calcbtn_click(object sender, eventargs e) { messagebox.show(calctotalcharges()); } } }

somewhere in code have assign value returned method variable , show/display variable. example:

int staycharcges = calcstaycharges();

let's in textbox user filled in '3'. staycharges '1050'. can show in label or display through messagebox:

resultlabel.text = string.format("charge: {0}", staycharges); //or resultlabel.tekst = staycharges.tostring() //only number //with messagebox messagebox.show(string.format("charge: {0}", staycharge);

c# methods return

No comments:

Post a Comment