Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

help please Need help making a script!!! any help?please

1 vue (au cours des 30 derniers jours)
john hollywood
john hollywood le 10 Mar 2014
Clôturé : MATLAB Answer Bot le 20 Août 2021
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| | *

Réponses (1)

Chandrasekhar
Chandrasekhar le 10 Mar 2014
Modifié(e) : Chandrasekhar le 10 Mar 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

Cette question est clôturée.

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by