Effacer les filtres
Effacer les filtres

How to give marks for a given answer

2 vues (au cours des 30 derniers jours)
Evan
Evan le 2 Oct 2023
Commenté : Guillaume le 4 Oct 2023
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 commentaire
Rik
Rik le 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.

Connectez-vous pour commenter.

Réponse acceptée

Guillaume
Guillaume le 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)
  2 commentaires
Evan
Evan le 4 Oct 2023
Thank u boss 👍
Guillaume
Guillaume le 4 Oct 2023
You are welcome :-)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by