c# - Accept integer numbers as input, one at a time, in a single field -


quick note - new c# apologize if stupid simple.

i having hard time trying complete simple c# task in book.

my task - create windows application accepting integer numbers input, 1 @ time, in single field. button should cause displaying number right below input field, if larger displayed number (or it’s first number processed). 0 (0) has been processed, stop accepting more input , display (above input field) sum of entered numbers.

here's have far -

using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.text; using system.threading.tasks; using system.windows.forms; using system.linq;   namespace windowsformsapplication2 {     public partial class form1 : form     {         public form1()         {             initializecomponent();             button1.click += new system.eventhandler(button1_click);             listofnumbers = new list<int>();         }          list<int> listofnumbers;          private void button1_click(object sender, eventargs e)         {             //convert input integer             int orginalinput = int.parse(textbox1.text);              //add numbers list             listofnumbers.add(orginalinput);              string txt = "";              foreach (int originalnumber in listofnumbers)             {                 //find numbers greater entered number                 int highernumber = listofnumbers.find(item => item > originalnumber);                  if (listofnumbers.count == 1 || originalnumber < highernumber)                 {                     txt += highernumber + " ";                     label1.text = txt;                 }               }              textbox1.clear();           }     } }  

i haven't started add inputs ( 0 (0) has been processed, stop accepting more input , display (above input field) sum of entered numbers.)

i'm still trying figure out first part of task.

problems have - --the first number displayed 0 though type different number. --it seems spit out random numbers if type in lower number typed.

any or pointers appreciated!

if(!listofnumbers.contains(0)){ // check 0 entered or not     int input = int.parse(textbox1.text);     listofnumbers.add(input);      if(input==0){  // if 0 entered calculate sum , set label text        int sum = listofnumbers.sum();        label1.text = sum.tostring();     }else // otherwise campare last label value , entered number , set label     {      int maxno = int.parse(label1.text);      if(input>maxno)      {         label1.text = input.tostring();      }     } } 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -