Using C# Console framework and having problems. This code has worked but no longer does. No names are outputted for the if statements. Although the highest, lowest and average score work perfectly. I need to use filler as it wont let me post much code? On a different machine this worked although now nothing outputs. I'm pretty sure its a logic error although it is copied word for word.
using (StreamReader SR = new StreamReader(@"ExamResults.txt"))
{
List<string> Name = new List<string>();
List<int> Scores = new List<int>();
int iNumber = int.Parse(SR.ReadLine());
int ScoreNumber = 0;
int Itotal = 0;
for (int iCounter = 1; iCounter <= iNumber; iCounter++)
{
Name.Add(SR.ReadLine());
ScoreNumber = (int.Parse(SR.ReadLine()));
Itotal = Itotal + ScoreNumber;
Scores.Add(ScoreNumber);
}
for (int Index = 0; Index <= iNumber; Index++)
{
if (Scores[Index] < 49)
{
Console.WriteLine(Name[Index] + "Got Grade U");
}
if (Scores[Index] > 49 && Scores[Index] + Scores[Index] < 59)
{
Console.WriteLine(Name[Index] + "Got Grade E");
}
if (Scores[Index] > 59 && Scores[Index] + Scores[Index] < 69)
{
Console.WriteLine(Name[Index] + "Got Grade D");
}
if (Scores[Index] > 69 && Scores[Index] + Scores[Index] < 79)
{
Console.WriteLine(Name[Index] + "Got Grade C");
}
if (Scores[Index] > 79 && Scores[Index] + Scores[Index] < 89)
{
Console.WriteLine(Name[Index] + "Got Grade B");
}
if (Scores[Index] > 89 && Scores[Index] + Scores[Index] < 100)
{
Console.WriteLine(Name[Index] + "Got Grade A");
}
Console.WriteLine("The average score is: " + Math.Round(Scores.Average()));
Console.WriteLine("");
Console.WriteLine("The highest score is: " + Scores.Max() + " belonging to " +
Name[Scores.IndexOf(Scores.Max())]);
Console.WriteLine("");
Console.WriteLine("The lowest score is: " + Scores.Min() + " belonging to " +
Name[Scores.IndexOf(Scores.Min())]);
Console.Read();
Aucun commentaire:
Enregistrer un commentaire