my problem program is not displaying values in data file properly. showing 0's in sorted fashion. not relaying actual numbers in ascending fashion.
====================================
the 25 numbers need read in , placed in array are: (only used 4 numbers keep post shorter.
10.5 20.1 33.0 45.9
=================================
my code far below: think issue in displayarray() method. writes out 0's this:
\users\joe\documents\visual studio 2013\projects\cis110\program11\prog11dat. opened 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 press key continue . . .
=======
class program11 { const string input_file_name = "\\users\\joe\\documents\\visual studio 2013\\projects\\cis110\\program11\\prog11dat.txt"; static double[] numarray = new double[25]; static streamreader filein; static void readfile() { if (file.exists(input_file_name)) { filein = (file.opentext(input_file_name)); console.writeline("{0} opened",input_file_name); } else { console.writeline("error: {0} not exist\n",input_file_name); consoleapp.exit(); } } static void displayarray() { (int = 0; < numarray.length; i++) console.write("{0} ", numarray[i]); } static void sortvaluesascending() { uint i, j, k; double tempvalue; (i=1; i<=(numarray.length); i++) { k = 1; (j = (i + 1 ); j <= numarray.length -1; j++) if (numarray[j] < numarray[k]) k = j; if (k>i) { tempvalue = numarray[k]; numarray[k] = numarray[i]; numarray[i] = tempvalue; } } } static void main(string[] args) { readfile(); displayarray(); sortvaluesascending(); displayarray(); } } }
its getting there, problem readfile
doesn't reading @ minute; nor add array of doubles
static void readfile() { list<string> lines = new list<string>(); if (file.exists(input_file_name)) { using(var sr = new streamreader(input_file_name)) { string line; while((line = sr.readline()) != null) { lines.add(line); } } } else { console.writeline("error: {0} not exist\n",input_file_name); consoleapp.exit(); } // have list of numbers strings here (lines) // need parse , assign these numarray // hint: loop , parse/tryparse }
i've intentionally left out how parsing learning :)
a second hint, in displayarray
, using padright