Looping with for, foreach, do, while
parent
6c7ba8624f
commit
009cdc3919
|
@ -26,12 +26,21 @@ namespace GradeBook
|
||||||
result.highGrade = double.MinValue;
|
result.highGrade = double.MinValue;
|
||||||
result.lowGrade = double.MaxValue;
|
result.lowGrade = double.MaxValue;
|
||||||
|
|
||||||
foreach (var grade in this.grades)
|
// foreach (var grade in this.grades)
|
||||||
|
// {
|
||||||
|
// result.lowGrade = Math.Min(grade, result.lowGrade);
|
||||||
|
// result.highGrade = Math.Max(grade, result.highGrade);
|
||||||
|
// result.Average += grade;
|
||||||
|
// }
|
||||||
|
|
||||||
|
var index = 0;
|
||||||
|
do
|
||||||
{
|
{
|
||||||
result.lowGrade = Math.Min(grade, result.lowGrade);
|
result.lowGrade = Math.Min(grades[index], result.lowGrade);
|
||||||
result.highGrade = Math.Max(grade, result.highGrade);
|
result.highGrade = Math.Max(grades[index], result.highGrade);
|
||||||
result.Average += grade;
|
result.Average += grades[index];
|
||||||
}
|
index += 1;
|
||||||
|
} while (index < grades.Count);
|
||||||
|
|
||||||
result.Average /= grades.Count;
|
result.Average /= grades.Count;
|
||||||
return result;
|
return result;
|
||||||
|
|
Loading…
Reference in New Issue