C# GUI application that stores an array and displays the highest and lowest numbers by clicking a button -
background:
this updated 13 hours ago have been researching , experimenting few. i'm new programming arena i'll short, i'm teaching myself c#
and i'm trying learn how have integers user's input textbox calculated button1_click appear on form. yes, class assignment think have handle on of not of it; that's why i'm turning guys.
problem:
i'm using microsoft visual studio 2010 in c# language, windows forms application , need create gui allows user enter in 10 integer values stored in array called button_click object. these values display highest , lowest values user inputted. thing array must declared above click() method.
this have come far:
namespace smallandlargegui { public partial class form1 : form { public form1() { initializecomponent(); } public void inputtext_textchanged(object sender, eventargs e) { this.text = inputtext.text; } public void submitbutton_click(object sender, eventargs e) { int uservalue; if(int.tryparse(inputtext.text, out uservalue)) { } else { messagebox.show("please enter valid integer text box."); } int x; x = convert.x.tostring(); int squaredresults = squared(x); int cubedresults = cubed(x); squared(x); squaredlabel.text = x.tostring() + " squared " + squaredresults.tostring(); cubedlabel.text = x.tostring() + " cubed " + cubedresults.tostring(); } public static int squared(int x) { x = x * x; return x; } public static int cubed(int x) { x = x * squared(x); return x; } } }
now can't run program because line 38 shows error message of: 'system.convert' not contain definition 'x' still have have array holds 10 integers textbox , declared above click() method. please guys, me? due yesterday.
this looks homework, should try bit more that. here do: parse string (say it's comma-separated list of numbers), cast each value int
, populate array. can either call .max()
/ .min()
methods or loop through values of array , max / min value. here bit of code:
int n = 10; int[] numbers = (from sn in system.text.regularexpressions.regex.split(inputtext.text, @"\s*,\s*") select int.parse(sn)).toarray(); int max = numbers.max(); int min = numbers.min(); //int max = numbers[0]; //int min = numbers[0]; //for(int = 1; < n; i++) //{ // if(max < numbers[i]) // { // max = numbers[i]; // } // if(min > numbers[i]) // { // min = numbers[i]; // } //}
Comments
Post a Comment