How to give marks for a given answer
1 view (last 30 days)
Show older comments
soal1 = 5;
while soal1 < 1 || soal1 > 4
soal1 = input(['1. Besar gaya gravitasi antara dua massa yang berjarak tertentu satu sama lain adalah \n ' ...
'1.berbanding lurus dengan jarak kedua benda \n ' ...
'2.berbanding terbalik dengan jarak kedua benda \n ' ...
'3.berbanding lurus dengan kuadrat jarak kedua benda \n ' ...
'4.berbanding terbalik dengan kuadrat kedua benda \n']);
if soal1==4
fprintf('correct answer \n')
elseif soal1==1 || soal1 == 2 || soal1 == 3
fprintf('false \n')
else
fprintf('please repeat \n')
end
end
if the user gave a correct answer, i want to give it a 10 mark
and if its incorrect 0 mark.
how to integrate the codes
thanks.
1 Comment
Rik
on 2 Oct 2023
It this as simple as inserting mark=0; and mark=10; to your current code? Otherwise I don't really understand what your question is and what the point would be of your unformatted code.
Accepted Answer
Guillaume
on 3 Oct 2023
Hello,
As Rik said, this is quite simple. You should add mark in your code, like this :
soal1 = 5;
mark = 0; % INIT VALUE
while soal1 < 1 || soal1 > 4
soal1 = input(['1. Besar gaya gravitasi antara dua massa yang berjarak tertentu satu sama lain adalah \n ' ...
'1.berbanding lurus dengan jarak kedua benda \n ' ...
'2.berbanding terbalik dengan jarak kedua benda \n ' ...
'3.berbanding lurus dengan kuadrat jarak kedua benda \n ' ...
'4.berbanding terbalik dengan kuadrat kedua benda \n']);
if soal1==4
mark = 10; % HERE
fprintf('correct answer \n')
elseif soal1==1 || soal1 == 2 || soal1 == 3
mark = 0; % HERE
fprintf('false \n')
else
fprintf('please repeat \n')
end
end
fprintf('Your mark is: %d\n', mark)
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!