Monday, 15 February 2010

c# - How to add a function that finds largest and smallest values and displays them -



c# - How to add a function that finds largest and smallest values and displays them -

i made programme asks come in few numbers less 100, , takes numbers entered , tells ones valid entries. want add together feature takes valid entries , finds smallest , largest numbers. after finds smallest , largest values want them displayed under says "invalid entries:." can help me adding this?

using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; namespace programming_exercise_2_chapter_6 { class programme { static void main(string[] args) { string answer; { console.clear(); header(); int number; string indata; list<int> validentries = new list<int>(); list<string> invalidentries = new list<string>(); while (true) { console.writeline("insert numbers less 100: "); indata = console.readline(); if (int32.tryparse(indata, out number)) { if (number <= 100 && number > 0) validentries.add(number); else invalidentries.add(number.tostring()); } else invalidentries.add(indata); console.writeline("press n stop. press come in continue."); indata = console.readline(); console.clear(); if (indata == "n"|| indata == "n") break; } displayentries(validentries, invalidentries); console.readline(); console.writeline("do want seek again?(enter y yes, or n no)"); reply = console.readline(); } while (answer == "y" || reply == "y"); } static void displayentries(list<int> validentries, list<string> invalidentries) { console.writeline("your valid entries were: "); foreach (int in validentries) console.writeline(i); console.writeline(); console.writeline("your invalid entries were: "); foreach (string s in invalidentries) console.writeline(s); } static void header() { console.writeline("\tnumber validation app"); console.writeline("please come in few numbers less 100.\nvalid entries displayed."); console.writeline(""); } } }

if understood question, want have smallest , largest entry integer list? in case can sort list , retrieve first / lastly entry of sorted list:

validentries.sort(); var smallest = validentries.first(); var highest = validentries.last();

is looking for?

c#

No comments:

Post a Comment