namespace learning
{
class Gradebook
{
public Gradebook()
{
grades = new List<float>();
}
public void AddGrade(float grade)
{
grades.Add(grade);
}
public Gradestatistic compute_statistics()
{
Gradestatistic stats = new Gradestatistic();
float sum = 0f;
foreach (float grade in grades)
{
sum = sum + grade;
}
stats.average_grade = sum / grades.Count;
return stats;
}
List<float> grades;
}
}
I am using two custom classes Gradebook and Gradestatistic respectively , my object of class gradestatistic is stats , average_grade is the member of class gradestatistic, when i built this program it shows error on stats.average_grade = sum / grades.Count; which is can not implicitly convert type float to learning.gradestatistic . learning is my project name. the code of gradestatistic class is
class Gradestatistic
{
public Gradestatistic highest_grade;
public Gradestatistic lowestgrade;
public Gradestatistic average_grade;
}
my program.cs code is
class Program
{
static void Main(string[] args)
{
Gradebook book = new Gradebook();
book.AddGrade(91);
book.AddGrade(89.9f);
Gradestatistic stats = book.compute_statistics();
}
}