Borrar filtros
Borrar filtros

How to give marks for a given answer

2 visualizaciones (últimos 30 días)
Evan
Evan el 2 de Oct. de 2023
Comentada: Guillaume el 4 de Oct. de 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 comentario
Rik
Rik el 2 de Oct. de 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.

Iniciar sesión para comentar.

Respuesta aceptada

Guillaume
Guillaume el 3 de Oct. de 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 comentarios
Evan
Evan el 4 de Oct. de 2023
Thank u boss 👍
Guillaume
Guillaume el 4 de Oct. de 2023
You are welcome :-)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by