Finished Pattern Matching with switch
This commit is contained in:
parent
dd47f5cf72
commit
41ca2586dc
@ -52,16 +52,27 @@ namespace GradeBook
|
||||
result.Average += grade;
|
||||
}
|
||||
|
||||
// var index = 0;
|
||||
// do
|
||||
// {
|
||||
// result.lowGrade = Math.Min(grades[index], result.lowGrade);
|
||||
// result.highGrade = Math.Max(grades[index], result.highGrade);
|
||||
// result.Average += grades[index];
|
||||
// index += 1;
|
||||
// } while (index < grades.Count);
|
||||
|
||||
result.Average /= grades.Count;
|
||||
|
||||
switch (result.Average)
|
||||
{
|
||||
case var d when d >= 90.0:
|
||||
result.Letter = 'A';
|
||||
break;
|
||||
case var d when d >= 80.0:
|
||||
result.Letter = 'B';
|
||||
break;
|
||||
case var d when d >= 70.0:
|
||||
result.Letter = 'C';
|
||||
break;
|
||||
case var d when d >= 60.0:
|
||||
result.Letter = 'D';
|
||||
break;
|
||||
default:
|
||||
result.Letter = 'F';
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -5,5 +5,6 @@ namespace GradeBook
|
||||
public double Average;
|
||||
public double highGrade;
|
||||
public double lowGrade;
|
||||
public char Letter;
|
||||
}
|
||||
}
|
@ -21,6 +21,7 @@ namespace GradeBook.Tests
|
||||
Assert.Equal(85.6, result.Average, 1);
|
||||
Assert.Equal(90.5, result.highGrade);
|
||||
Assert.Equal(77.3, result.lowGrade);
|
||||
Assert.Equal('B', result.Letter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user