フィルターのクリア

How to give marks for a given answer

2 ビュー (過去 30 日間)
Evan
Evan 2023 年 10 月 2 日
コメント済み: Guillaume 2023 年 10 月 4 日
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 件のコメント
Rik
Rik 2023 年 10 月 2 日
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.

サインインしてコメントする。

採用された回答

Guillaume
Guillaume 2023 年 10 月 3 日
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 件のコメント
Evan
Evan 2023 年 10 月 4 日
Thank u boss 👍
Guillaume
Guillaume 2023 年 10 月 4 日
You are welcome :-)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by