for loop for an interactive program
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi Guys, I have got the foloowing task, so far I have created few parts but not been able to do input of variable part.
Interactive Program: Write a program that measures a person's reaction time when measures keystrokes. The rand and round commands are intended to give the user an integer between 0 and 10, which he should immediately type on the keyboard, while the
elapsed time is measured [tic, toc]. The procedure should be repeated ten times. The mean value of the reaction time (between showing and entering) is displayed as a result in a separate window [msgbox]. If the person makes an incorrect entry, it must program can be canceled with a message.Expand the program so that the following are dependent on the reaction time (mean value).
Messages are displayed:
T ≤ 0.5 S ek You are very fast!!
T ≤ 1 S ek You are fast !!
T ≤ 2 sec Not very impressive !!
T > 2 sec A turtle would be faster than you!!
tic
n=10
for x= 1:n
x=randi([1 10],1,1)
msgbox("x")
input="Bitte Zahl eingeben"
end
%if t<=0,5
disp("Du bist sehr schnell !!")
%else 0.5<t>=1
disp("Du bist schnell !!")
%elseif 1<t<=2
disp("Nicht sehr beeindruckened!!")
%elseif t>2
disp("Eine Schildkröte wäre schneller als du !!")
0 Commenti
Risposte (1)
Shoaib iqbal
il 31 Ott 2022
Hi Abhishek
I understand that you are trying to measure a person’s reaction time using a task you have created.
To measure the elapsed time between showing and entering the integer value, you can use tic toc. Following code snippet may solve your problem.
for i = 1:2
x = randi(10);
tic
display(x);
prompt = "input ";
y = input(prompt);
t = toc;
if (y == x)
if (t<=0.5)
disp("you are very fast");
elseif (t>0.5 && t<=1)
disp("you are fast");
elseif (t>1 && t<=2)
disp("Not very impressive");
else
disp("A turtle would be faster than you");
end
else
disp("wrong value entered")
end
end
Hope this is helpful.
1 Commento
Walter Roberson
il 31 Ott 2022
This was a homework assignment, so we discourage providing complete solutions
Vedere anche
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!