Simple average program - Programmers Heaven

#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# Simple average program

Posts: 3Member
I'm trying to make a program that computes a grade average, tells how many students are passing and how many are above average. I've got the above passing grades and the grade average figured. I need help figuring out how to show how many grades are above average. Heres my source code, any input is appreciated.

function avg
sum = 0; % sum of grades
counter = 0;
aboveaverage = 0;
n = input('input number of students:');%how many students?
for i = 1:n
grade(i) = input('input grade: '); % students grades
sum = sum + grade(i);
if(grade(i) >= 6)
counter = counter + 1;
end

avg = sum/n;% grade average

end

if (grade(i) >= (sum/n))
aboveaverage=aboveaverage+1; %calculate number of grades above avg
end

fprintf(1,'Avg = %g With %g passing grades
',avg,counter);

fprintf(1,'Students above average: = %g
',aboveaverage);

Sign In or Register to comment.