How to I get the average of the inputs from this?
Mostrar comentarios más antiguos
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)
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!