troubleshooting Question

StreamReader C# urgent

Avatar of Ibrahimsairafi
Ibrahimsairafi asked on
C#
1 Comment1 Solution1817 ViewsLast Modified:

I have file called "list.txt" that contains :
971942 |Usman Ibrahim    | 87     | 77 |      53
971986 |Nasir Muhammad | 84      | 69 |      65
972706 |Farouk Isah         | 94      | 99 |      80
973069 |Shehu Amir     | 90      | 77 |      49
973178 |Yakub Umar     | 98      | 78 |      63
973410 |Abdullah Sani  | 93      | 82 |      48
974079 |Bashir Othman  | 85      | 79 |      89
974130 |Junaidu Tukur  | 84      | 82 |      61
974201 |Adamu Hassan   | 93      | 99 |      76
974705 |Hussain Ahmad  | 89      | 94 |      71

---------------------------------------------------------------

I alredy calculate the avrege and split '|' which the result like this


971942 Usman Ibrahim     87      77       53   72.333333333333
971986 Nasir Muhammad  84       69       65   72.666666666666
972706 Farouk Isah          94       99       80   91
973069 Shehu Amir          90       77       49   72
973178 Yakub Umar         98       78       63   79.666666666667
973410 Abdullah Sani       93       82       48   74.333333333333
974079 Bashir Othman     85       79       89   84.333333333333
974130 Junaidu Tukur      84       82       61   75.666666666667
974201 Adamu Hassan     93       99       76   89.333333333333
974705 Hussain Ahmad    89       94       71   84.666666666667

----------------------------------------------------------------------------

Now I want to know how to calculate the avreage of each exam
----------------------------------------------------------
this my code

/*
 * Created by SharpDevelop.
 * User: sairafia
 * Date: 11/07/1426
 * Time: 07:54 ?
 *
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
 
 using System;
 using System.IO;
 
 class StreamRead{
       
       static void Main(string [] args){
             
             string strLine;
             
             string [] str;
             
             char [] chararray=new char [] {'|'};
       
        double exam1, exam2, exam3, average=0;
             
             

             try{
             FileStream aFile= new FileStream("list.txt",FileMode.Open);
             
             StreamReader sr= new StreamReader(aFile);
                   
             strLine=sr.ReadLine();
       
                   
             while(strLine!=null){
                         
             str=strLine.Split(chararray);
                   
             for(int x=0;x<=str.GetUpperBound(0);x++){
                   
             Console.Write(str[x]);
                   
                   
             exam1 = Double.Parse(str[2]);
             exam2 = Double.Parse(str[3]);
             exam3 = Double.Parse(str[4]);
             average = (exam1 + exam2 + exam3)/3;

                         }
                         
                         Console.WriteLine(" "+average);
                         
                         
                         strLine=sr.ReadLine();
                   }
             
             sr.Close();
 Console.ReadLine();
             }
             
             catch(IOException e)
             {
             
             Console.WriteLine("  Not Found ");
             Console.WriteLine(e.ToString());
             Console.ReadLine();
             
             return;
       }
       return;
 }
 
                   
             }
       




Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 1 Comment.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros