Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Lottery The lottery game matches three different integer numbers between 1 and 1

ID: 3596126 • Letter: L

Question

Lottery The lottery game matches three different integer numbers between 1 and 10. Winning depends on how many matching numbers are provided by a player. The player provides three different integers between 1 and 10 - If there is a match of all 3 numbers, the winning $1000 - If there is a match with 2 numbers, the winning $ 10 - If there is a match with 1 number, the winning $ 1 - With no match, the winning is $0 Write a function Lottery3 that checks three numbers provided by a player and determine the winning amount. If the user mistakenly enters same number twice/thrice and if that number matches one of the winning numbers, the code should count that number only once and display correct result. The player doesn't have to guess the order of numbers The input to the function Lottery3 can have up to two input arguments. The first input argument is a row array numbers with 3 numbers. If thee second argument input testCode is present, and is a row vector of 3 values, the function Lottery3 uses the code in testCode as the three winning numbers (the test must be three different integer numbers between 1 and 10), else three different numbers will be automatically generated by testCode The ouput should return the variable winnings and the three winning numbers in the row array winNumbers Hint: Make use of the internal functions any and nargin Restriction: The function must use switch-case statements to determine the winning

Explanation / Answer

function [winning, winNumbers] = Lottery3(numbers, testCode)
winNumbers = randperm(10, 3);
if nargin == 2
winNumbers = testCode;
end
count = 0;
if any(winNumbers(:) == numbers(1))
count = count +1;
end
  
if numbers(1) ~= numbers(2) && any(winNumbers(:) == numbers(2))
count = count +1;
end
  
if (numbers(1) ~= numbers(3) && numbers(2) ~= numbers(3)) && any(winNumbers(:) == numbers(3))
count = count +1;
end
  
switch count
case 0
winning = 0;
case 1
winning = 1;
case 2
winning = 10;
case 3
winning = 1000;
end
end

code to call your function

testCode=[1,2,3]; numbers=[1,2,5];
[winning, winNumbers] = Lottery3(numbers, testCode)

sample run

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote