educative.io

Whats wrong with this average code?

This was my code for computing averages in the assessment

class Average {
public:
int num1;
int num2;
int num3;
float avg=0;
//define data members here
Average(int n1,int n2,int n3) {
//write your code here
num1=n1;
num2=n2;
num3=n3;
avg=(n1+n2+n3)/3;
}

void print_average() {
cout << avg;
//write your code here
}
};

I tested it against the sample input provided in the problem
Average obj(1,2,3);
obj.print_average();
In general the fact theres no explanation on whats happening in the assessments is quite irritating. It just says did not pass doesn’t even say what it needs to pass.


Course: Learn Object-Oriented Programming in C++ - Learn Interactively
Lesson: Conclusion - Learn Object-Oriented Programming in C++