Azzera filtri
Azzera filtri

How to give marks for a given answer

1 visualizzazione (ultimi 30 giorni)
Evan
Evan il 2 Ott 2023
Commentato: Guillaume il 4 Ott 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 Commento
Rik
Rik il 2 Ott 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.

Accedi per commentare.

Risposta accettata

Guillaume
Guillaume il 3 Ott 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)

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by