So in my homework I was given this problem:
"Prompt the user to enter numeric grades (one at a time) within a while loop. Any number of grades can be entered.
• Determine the number of grades in each grade range using a standard 10 point scale: A (90 or higher), B (80-90), C (70-80), D (60-70), and F (0-60).
• Determine the maximum, minimum, and average grade.
• Display the results including the number of grades, maximum grade, minimum grade, and the number of grades in each grade range.
• Test the program for cases including 4 grades, 10 grades, and 20 grades with the grades reasonably distributed between the grades ranges."
And I could really use some help getting started!
Thanks so much!

댓글 수: 3

Geoff Hayes
Geoff Hayes 2016년 3월 2일
Hugh - please clarify what you need help with. Describe what you have attempted, including the code that you have written to solve this problem. If you are observing a particular error, then copy and paste the full error message to the body of this question.
grade=0;
total=0;
counter =-1;
disp('When done entering grades enter "-1"');
prompt = ('Input another Grade: ');
i=1;
while (grade ~= -1)
total = total + grade;
counter = counter +1;
grade = input(prompt);
grade1(i) = grade;
i=i+1;
end
Average = (total/counter);
disp('Average = ');
disp(Average);
disp('Min = ')
MIN = min(grade1(1,:));
disp(MIN)
disp('Max = ')
MAX = max(grade1);
disp(MAX)
So the problem I'm having is selecting all the values in my minimum array except -1
Hugh Benfer
Hugh Benfer 2016년 3월 2일
Also I'm not sure how to count how many As,Bs,Cs etc there are

댓글을 달려면 로그인하십시오.

 채택된 답변

Geoff Hayes
Geoff Hayes 2016년 3월 2일

1 개 추천

Hugh - delay adding your grade to the array until you know for sure whether it is valid or not. For example, you can replace your while loop with the following
k=1;
allGrades = [];
while true
grade = input(prompt);
if grade < 0
break;
end
allGrades(k) = grade;
k=k+1;
end
Note how k is used instead of i (MATLAB uses i and j to represent the imaginary number). Also, we break out of the loop once we know that the grade is negative. I've avoided using the total and counter variables because you can use sum and length to determine both.
As for counting your grades, since there are five (A,B,C,D,F) then use an array initialized with five elements to manage the counts for these grades. Loop over your allGrades array and increment the appropriate index that corresponds to the letter grade of the mark. (Or just do this whenever the user enters in a new grade.)

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Scripts에 대해 자세히 알아보기

질문:

2016년 3월 2일

답변:

2016년 3월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by