Question

Lottery The lottery game matches three different integer numbers between 1 and 10. Winning depends on...

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 the 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.

Example #1:

winning = Lottery3( [1,2,1],[1,2,3])

produces

winning =

    10

Example #2:

    [winning,winNumbers] = Lottery3( [1,2,3])

produces

winning =

     3

winNumbers =

     8     5     3

function [winning,winNumbers] = Lottery3(numbers,testCode)

winNumbers=randperm(10,3); % generates three different integers between 1 and 10

% Insert code here to see is winNumbers should be overwritten with testCode %

% Insert code here to determine how many winning numbers are present %

% Insert code to calculate the winnings using switch %

end

Homework Answers

Answer #1

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

winning =  10
winNumbers =

   1   2   3
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Suppose that in a lottery game you are to pick five different integers between 1 and...
Suppose that in a lottery game you are to pick five different integers between 1 and 50, including 1 and 50, and a sixth integer between 1 and 40, including 1 and 40. a) What is the probability that you win the jackpot where the first five numbers that you picked match the five numbers drawn and the sixth number you pick matches the sixth number drawn? b) What is the probability of winning a smaller jackpot where you match...
A player in the Powerball lottery picks five different integers between 1 and 69, inclusive, and...
A player in the Powerball lottery picks five different integers between 1 and 69, inclusive, and a sixth integer between 1 and 26, which may duplicate one of the earlier five integers. The player wins the jackpot if all six numbers match the numbers drawn. a) What is the probability that a player wins the jackpot? b) What is the probability that a player wins $1,000,000, which is the prize for matching the first five numbers, but not the sixth...
In the lottery game called 5/21, a player picks five numbers from 1 to 21. Enter...
In the lottery game called 5/21, a player picks five numbers from 1 to 21. Enter all answers as a decimal (not a percent), rounded to five decimal places. a) If all five of the numbers match the ones that are drawn, the player wins first prize. What is the probability of winning this prize? b) If four of the five numbers match the ones that are drawn, but the other number doesn't match, the player wins second prize. What...
2. Winning the jackpot in a particular lottery requires that you select the correct three numbers...
2. Winning the jackpot in a particular lottery requires that you select the correct three numbers between 1 and 28 and, in a separate​ drawing, you must also select the correct single number between 1 and 32. Find the probability of winning the jackpot. 3. Winning the jackpot in a particular lottery requires that you select the correct five numbers between 1 and 40 and, in a separate​ drawing, you must also select the correct single number between 1 and...
6. Winning the jackpot in a particular lottery requires that you select the correct three numbers...
6. Winning the jackpot in a particular lottery requires that you select the correct three numbers between 1 and 54 ​and, in a separate​ drawing, you must also select the correct single number between 1 and 23. Find the probability of winning the jackpot. (Type an integer or simplified​ fraction.)
In a lottery? game, the jackpot is won by selecting six different whole numbers from 1...
In a lottery? game, the jackpot is won by selecting six different whole numbers from 1 through 35 and getting the same six numbers? (in any? order) that are later drawn. In the Pick 3 ?game, you win a straight bet by selecting three digits? (with repetition? allowed), each one from 0 to? 9, and getting the same three digits in the exact order they are later drawn. The Pick 3 game returns ?$500 for a winning? $1 ticket. Complete...
Winning the jackpot in a particular lottery requires that you select the correct three numbers between...
Winning the jackpot in a particular lottery requires that you select the correct three numbers between 1 and 41 ?and, in a separate? drawing, you must also select the correct single number between 1 and 56. Find the probability of winning the jackpot.
Winning the jackpot in a particular lottery requires that you select the correct five numbers between...
Winning the jackpot in a particular lottery requires that you select the correct five numbers between 1 and 30 ​and, in a separate​ drawing, you must also select the correct single number between 1 and 20. Find the probability of winning the jackpot. The probability of winning the jackpot is? ​(Type an integer or simplified​ fraction.)
In a lottery game, the jackpot is won by selecting five different whole numbers from 1...
In a lottery game, the jackpot is won by selecting five different whole numbers from 1 through 41 and getting the same five numbers (in any order) that are later drawn. In the Pick 3 game, you win a straight bet by selecting three digits (with repetition allowed), each one from 0 to 9, and getting the same three digits in the exact order they are later drawn. The Pick 3 game returns $500 for a winning $1 ticket. Complete...
Write a PHP code that: 1- Creates an array that holds 10 random integer numbers between...
Write a PHP code that: 1- Creates an array that holds 10 random integer numbers between 1 and 100. 2- Moves all multiple of 3-numbers in the array that created in part-a into a new array. 3- Moves all multiple of 5-numbers in the array that created in part-a into a new array. 4- Find the maximum and the minimum multiple of 3-numbers, if exist. 5- Find the maximum and the minimum multiple of 5-numbers, if exist. 6- Prints the...