MUST PROGRAM USING MATLAB! Assume that winning numbers for this week\'s Powerbal
ID: 2082509 • Letter: M
Question
MUST PROGRAM USING MATLAB!
Assume that winning numbers for this week's Powerball lottery is: WB = [01, 25, 28, 31, 54] & PB = 02 Write a MATLAB script that asks the user to provide the White Balls numbers and Power Ball number on his/her ticket and reports the prize according the following rules: if only PB number matches, then prize is $2 if PB and 1 of the WB numbers match, then prize is $4 if PB and 2 of the WB numbers match, then prize is $7 if 3 of WB numbers match, then prize is $7 if PB and 3 of the WB numbers match, then prize is $100 if 4 of WB numbers match, then prize is $100 if PB and 4 of the WB numbers match, then prize is $50,000 if 5 of WB numbers match, then prize is $1,000,000 if PB and all the WB numbers match, then it is a Jackpot. The program first needs to make sure that inputs are valid numbers, i.e. 5 non-repetitive positive integers between 1 and 69 for WB numbers and one positive integer between 1 and 26 for PB number.Explanation / Answer
MATLAB code:
clear all
close all
clc
WB=[01,25,28,31,54];
PB=02;
whiteball=input('Enter 5 non-repetative whiteball numbers : ');
powerball=input('Enter powerball number : ');
yy=0;
i=1;
j=1;
k=0;
for i=1:size(WB,2)
for j=1:5
if whiteball(j)==WB(i)
k=k+1;
end
end
end
yy
if powerball==PB && k==0
yy=2;
elseif powerball==PB && k==1
yy=4;
elseif powerball==PB && k==2
yy=7;
elseif k==3
yy=7;
elseif powerball==PB && k==3
yy=100;
elseif k==4
yy=100;
elseif powerball==PB && k==4
yy=50000;
elseif k==5
yy=1000000;
elseif powerball==PB && k==5
disp('Jackpot')
end
sample outputs
Enter 5 non-repetative whiteball numbers : [26,29,100,09,50]
Enter powerball number : 02
yy =
2
>>
Enter 5 non-repetative whiteball numbers : [01,29,100,09,50]
Enter powerball number : 02
yy =
4
>>
Enter 5 non-repetative whiteball numbers : [01,25,100,09,50]
Enter powerball number : 02
yy =
7
>>
Enter 5 non-repetative whiteball numbers : [01,25,28,09,50]
Enter powerball number : 10
yy =
7
>>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.