Ibrahimsairafi
asked on
StreamReader C# urgent
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",File
StreamReader sr= new StreamReader(aFile);
strLine=sr.ReadLine();
while(strLine!=null){
str=strLine.Split(chararra
for(int x=0;x<=str.GetUpperBound(0
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.ToStri
Console.ReadLine();
return;
}
return;
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.