Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Simple average program

weswaitmanweswaitman 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.