How to I get the average of the inputs from this?

3 views (last 30 days)
My code is as follows:
A=0;B=0;C=0;D=0;F=0;
x=input('Enter an exam grade from 0 to 100: '); %Prompts the user to input a value to begin the loop
while (x>=0) && (x<=100)
if x<60
F=F+1; %Adds to the total amount of grades in the category
elseif x<70
D=D+1;
elseif x<80
C=C+1;
elseif x<90
B=B+1;
elseif x<=100
A=A+1;
end %ends conditional statements to move to next input
x=input('Enter an exam grade from 0 to 100: '); %input runs within the loop until a value less than 0 or greater than 100 is entered
end
fprintf('There are a total of %.0f A''s scored on the exam.\n',A)
fprintf('There are a total of %.0f B''s scored on the exam.\n',B)
fprintf('There are a total of %.0f C''s scored on the exam.\n',C)
fprintf('There are a total of %.0f D''s scored on the exam.\n',D)
fprintf('There are a total of %.0f F''s scored on the exam.\n',F)

Accepted Answer

Image Analyst
Image Analyst on 16 Mar 2015
To get the mean score within each grade letter, you will have to sum them up
if x<60
F=F+1; %Adds to the total amount of grades in the category
FSum = FSum + x;
and so on for the other letters. Be sure to set FSum = 0 before the loop starts. Then after the look, just get the means
AMean = ASum / A;
BMean = BSum / B;
CMean = CSum / C;
DMean = DSum / D;
FMean = FSum / F;

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!