c# - Calculate all the values in textfile -




i have make program allows admin calculate total revenues each business type.

i have stored gained revenues each type in separate text files ie. .mobile.txt , .kiosk.txt , .daily.txt

the content each type in text file this

10 60 30 

so far code i've generated, still doesn't work

 private void report_load(object sender, eventargs e)     {          list<double> kiosk = new list<double>();         list<double> daily = new list<double>();         list<double> mobile = new list<double>();         foreach (string line in file.readalllines(@".kiosk.txt"))         {             kiosk.add(double.parse(line));         }          foreach (string line in file.readalllines(@".mobile.txt"))         {             mobile.add(double.parse(line));          }          foreach (string line in file.readalllines(@".daily.txt"))         {             daily.add(double.parse(line));         }          double sum_kiosk = kiosk.sum();         double sum_mobile = mobile.sum();         double sum_daily = daily.sum();          messagebox.show("total revenue kiosk:" + sum_kiosk + "\ntotal revenue mobile:" + sum_mobile + "\ntotal revenue:" + sum_daily);     } 

and error exception states "input string not in correct format". can't seem find problem one

how solve error? or there better alternative make feature work?

you can use code compute numbers. , use variable instead of list

double mobile = 0; foreach (string line in file.readalllines(@"data.txt")) {     double temp;     double.tryparse(line, out temp);     mobile += temp; } 




wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -