我正在尝试打印“NONE”出现的时间,因为我打印的所有其他信息都是准确的。我相信这可能是我正在用我的价值观做的事情,但每次我修复某些东西并让我的代码编译时,我都会得到零作为我的答案。为什么是这样?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace ConsoleApplication33
{
class Program
{
static void Main(string[] args)
{
FileStream fStream = new FileStream("Students.txt", FileMode.Open, FileAccess.Read);
StreamReader inFile = new StreamReader(fStream);
string inValue;
string[] values;
double GPA;
double total = 0;
double counter = 0;
double count = 0;
double counti = 0;
List<string> Anderson = new List<string>(); //Anderson
List<string> gpa = new List<string>(); //GPA
List<string> noemail = new List<string>(); // email
while (!inFile.EndOfStream)
{
inValue = inFile.ReadLine();
values = inValue.Split(" ".ToCharArray());
if (inValue.StartsWith("(LIST (LIST "))
{
values = inValue.Split(" ".ToCharArray());
GPA = double.Parse(values[8]);
total = total + GPA;
counter++;
}
if (values[2] == "'Anderson")
{
Anderson.Add(values[2]);
count++;
}
if (values[2] == " ")
{
counter++;
}
if (values[6] == "'NONE")
{
noemail.Add(values[6]);
counti++;
}
}
double average = (double)total / (double)counter;
Console.WriteLine("The average gpa is..." + average.ToString());
Console.WriteLine("Total last names with Anderson is..." + count.ToString());
Console.WriteLine("Total number of students is..." + counter.ToString());
Console.WriteLine("Total is..." + counti.ToString());
}
}
}