Info
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
help please Need help making a script!!! any help?please
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
function mathgame = mathgame()
disp('Welcome to the math game!');
count = 1;
correct = 0;
incorrect = 0;
rand1 = 1 + 9 * rand(1);
rand2 = 1 + 9 * rand(1);
sprintf(%d: %d + %d =",count,rand1,rand2)
answer = input('');
if answer == rand1+rand2
disp('Correct!');
correct = correct +1;
else
disp('Incorrect!');
incorrect = incorrect+1;
end
again = input('Again','s');
while strcmp(again,'y')==1
count = count+1;
rand1 = 1 + 9 * rand(1);
rand2 = 1 + 9 * rand(1);
sprintf(%d: %d + %d =",count,rand1,rand2);
answer = input('');
if answer == rand1+rand2
disp('Correct!');
correct = correct +1;
else
disp('Incorrect!');
incorrect = incorrect+1;
end
again = input('Again','s');
end
sprintf('Correct: %d (%.2f %%), Incorrect %d (%.2f %%)',correct,(100.0*correct/count),incorrect,(100.0*incorrect/count))
end
mathgame();
- | |
- * For some reason my code is not working , can you please help me. Thank you for your time| | *
0 comentarios
Respuestas (1)
Chandrasekhar
el 10 de Mzo. de 2014
Editada: Chandrasekhar
el 10 de Mzo. de 2014
Please check if this satisfies your requirement
function mathgame = mathgame()
clc;
disp('Welcome to the math game!');
count = 1;
correct = 0;
incorrect = 0;
rand1 = 1 + 9 * rand(1);
rand2 = 1 + 9 * rand(1);
sprintf('%d: %d + %d =',count,rand1,rand2)
answer = input('guess the result of the sum of random numbers: ');
sum = rand1+rand2;
if answer == sum
disp('Correct!');
correct = correct +1;
else
disp('Incorrect!');
incorrect = incorrect+1;
end
sprintf('Correct: %d (%.2f %%), Incorrect %d (%.2f %%)',correct,(100.0*correct/count),incorrect,(100.0*incorrect/count))
again = input('Again? ','s');
while strcmp(again,'y')==1
count = count+1;
rand1 = 1 + 9 * rand(1);
rand2 = 1 + 9 * rand(1);
sprintf('%d: %d + %d =',count,rand1,rand2)
answer = input('guess the result of the sum of random numbers: ');
sum = rand1+rand2;
if answer == sum
disp('Correct!');
correct = correct +1;
else
disp('Incorrect!');
incorrect = incorrect+1;
end
again = input('Again? ','s');
sprintf('Correct: %d (%.2f %%), Incorrect %d (%.2f %%)',correct,(100.0*correct/count),incorrect,(100.0*incorrect/count))
end
end
0 comentarios
La pregunta está cerrada.
Ver también
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!