Info

此问题已关闭。 请重新打开它进行编辑或回答。

Help me out finding errors

1 次查看(过去 30 天)
Raed Noor
Raed Noor 2019-11-11
关闭: MATLAB Answer Bot 2021-8-20
Hey there
I have a homework to calculate the total grade on some quizzes. I know there are some error, could you please help me out finding and fixing them??
A = cell(20,7);
i = 1;
x = input ('Enter the student''s name ( or to termate ):','s');
while(~strcmp(x,'0'))
A{i,1} = x;
A{i,2} = input('Enter the grade for the exam 1 ( out of 20) ');
A{i,3} = input('Enter the grade for the exam 2 ( out of 20) ');
A{i,4} = input('Enter the grade for the exam 3 ( out of 20) ');
A{i,5} = input('Enter the grade for the exam 4 ( out of 20) ');
A{i,6} = A{i,2};
for j = 2:5
A{i,6} = A{i,6} + A{i,j};
end
z = floor(A{i,6}/10);
if (z < 6)
A{i,7} = 'F';
elseif (z < 7)
A{i,7} = 'D';
elseif (z < 8)
A{i,7} = 'C';
elseif (z < 9)
A{i,7} = 'B';
else (z < 9)
A{i,7} = 'A';
end
x = input ('Enter the student''s name ( or to termate ):','s');
i = i+1
end
I’m receiving this error!
Enter the grade for the exam 1 ( out of 20) Attempt to execute SCRIPT test as a function: /MATLAB Drive/test.m
Error in HM11 (line 8) A{i,2} = input('Enter the grade for the exam 1 ( out of 20) ');
  4 个评论
Walter Roberson
Walter Roberson 2019-11-12
编辑:Walter Roberson 2019-11-12
What about the fprintf() ? Your question does not mention fprintf()
fprintf('Student name: "%s", grade: "%s"\n', A{i,1}, A{i,7});
By the way, your code is very trusting that none of the responses will be nan or infinite, and that no-one will have a perfect score...And have a close close look at what you are comparing each value to.
Raed Noor
Raed Noor 2019-11-12
It's my prof's and he want's me to fix it. If it was mine, it'll be way to sampler. I hope it works now. Thank!

回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by