E) Design a well-packaged MATLAB program, with user-friendly interface for the following game: [20 Marks] (i) Two players, A and B, play a game called Lotto by Two Players. The Lotto machine generates a random lotto number in the range 0-50. They tak

1 vue (au cours des 30 derniers jours)
Design a well-packaged MATLAB program, with user-friendly interface for the following game: [20 Marks] (i) Two players, A and B, play a game called Lotto by Two Players. The Lotto machine generates a random lotto number in the range 0-50. They take turns choosing any number, positive or negative to build-up their total to the lotto number. Player A starts and may choose any number. After each move, the number chosen is added to a common running total. If the total exceeds the lotto number, a message indicating that the total is too high should be displayed, similarly the opposite if the number is too low. For example, a random lotto number of 45 is generated (hidden). A starts with 25(total=25), the script now displays that the total is too low. B then chooses 25(total=50). The script now says the total is too high. A chooses -10 (total 40), and so forth. Write a script file to simulate the game that allows each player to correct the total 20 times. If there is no matching total after 20 chances for each player, the player whose previous guess brought the total closest to the lotto number wins, otherwise they share the lotto winnings( if both equally closer).
  3 commentaires
MHLAWAKHE VATSHA
MHLAWAKHE VATSHA le 16 Oct 2019
clc;
clear;
L = randi([0 50])
total_sum = 0
chances = 0
A = input('choose number')
B = input('choose number')
if A == L
fprintf('\A won\n')
elseif B == L
fprintf('\B won \n')
else
total_sum = A + B + total_sum
chances = chances + 1
end
if total_sum < L
fprintf('\numrber too low\n')
elseif total_sum > L
fprintf('\number toohigh\n')
else
fprint('\ the play that brought the number closer to L wins if non both win and share the win\m')
while chances <= 20
end
end
John D'Errico
John D'Errico le 16 Oct 2019
What is the problem though? Where is your question?

Connectez-vous pour commenter.

Réponses (1)

MHLAWAKHE VATSHA
MHLAWAKHE VATSHA le 17 Oct 2019
clc;
clear;
L = randi([0 50])
total_sum = 0
chances = 0
A = 0
B = 0
while chances <= 20
A = input('choose number')
B = input('choose number')
if total_sum < L
fprintf('\n total too low\n')
elseif total_sum > L
fprintf('\n total too high\n')
else
end
if A == L || B == L
end
total_sum = total_sum + A + B;
chances = chances + 1;
end
if total_sum == L || total_sum ~= L
fprintf('\n the player that brought the total closest to L wins if both of the player they share the win\n')
end

Catégories

En savoir plus sur Strategy & Logic dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by