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

answer the question in matlab code 14092934 1/courses/ECE72-03-74786-2177/ECE72

ID: 3594471 • Letter: A

Question



answer the question in matlab code

14092934 1/courses/ECE72-03-74786-2177/ECE72 hw5.pdf sufficient comments to explain what your code is doing, making sure to follow the format for comments in a function discussed in class. 1. Write a program that will play a guessing game. Have the user guess an integer he user guesses the random number correctly then they win, if not then they lo Your program should allow the user to continue to g the user enters a 0 then the game ends. When the game ends the number of times the user wins and the total number of games played should be displayed to the screen. If the user enters something other than 0, 1, 2, 3, 4, or 5 then the program should prompt the user for another guess (in other words, you should do "error checking" without using the error function, which would end the program) 1 You with every valid entry should also plot the number of times the computer won with a solid blue line of width 1.1 and + markers, the number of times the user won with a dotted red line with square markers and a line width of 1.1, and the difference between the above two numbers (this value shouldn't be negative) plotted as a green line of width 1.1 with a dash dot line and asterisk markers. You should have a legend which describes these different lines in the top left corner (read the legend documentation), and an appropriate title, of size 18 font. After every entry, this plot should be created on figure 1, and should be formatted similar to the example below: Random Guess Game Results

Explanation / Answer


set =1;
m=5;
l=1;
error=true;
total=0;
userwin=0;
systemwin=0;
system_plot = [];
user_plot = [];

prompt= 'Give an integer value';
n=input(prompt);
while set==1
if ~ error
prompt= 'Give an integer value';
n=input(prompt);
end
while error
if(~(abs(round(n)-n) < eps))
prompt='Enter Integer:';
n=input(prompt);
else
error=false;
break;
end
end
error=true;
while error
if n==0
set=0;
error=false;
break;
else
if ~(n >0 and n<=5)
prompt='Another Guess:';
n=input(prompt);
error=true;
break;
else
error=false;
total=total+1;
out = randperm(m,l);
if out==n
userwin=userwin+1;
else
systemwin=systemwin+1;
end
system_plot(total)=systemwin;
user_plot(total)=userwin;
x=1:1:total;
plot(x,system_plot,'b+','LineWidth',1.1)
hold on
plot(x,user_plot,'rsquare','LineWidth',1.1)
plot(x,system_plot-user_plot,'_.g*','LineWidth',1.1)
hold off
legend('Times Computer Win','Times User win','Difference')
title('Figure1', 'FontSize',18);
end
end
end
end

set =1;
m=5;
l=1;
error=true;
total=0;
userwin=0;
systemwin=0;
system_plot = [];
user_plot = [];

prompt= 'Give an integer value';
n=input(prompt);
while set==1
if ~ error
prompt= 'Give an integer value';
n=input(prompt);
end
while error
if(~(abs(round(n)-n) < eps))
prompt='Enter Integer:';
n=input(prompt);
else
error=false;
break;
end
end
error=true;
while error
if n==0
set=0;
error=false;
break;
else
if ~(n >0 and n<=5)
prompt='Another Guess:';
n=input(prompt);
error=true;
break;
else
error=false;
total=total+1;
out = randperm(m,l);
if out==n
userwin=userwin+1;
else
systemwin=systemwin+1;
end
system_plot(total)=systemwin;
user_plot(total)=userwin;
x=1:1:total;
plot(x,system_plot,'b+','LineWidth',1.1)
hold on
plot(x,user_plot,'rsquare','LineWidth',1.1)
plot(x,system_plot-user_plot,'_.g*','LineWidth',1.1)
hold off
legend('Times Computer Win','Times User win','Difference')
title('Figure1', 'FontSize',18);
end
end
end
end

set =1;

m=5;

l=1;

error=true;

total=0;

userwin=0;

systemwin=0;

system_plot = [];

user_plot = [];

prompt= 'Give an integer value';

n=input(prompt);

while set==1

if ~ error

prompt= 'Give an integer value';

n=input(prompt);

end

while error

if(~(abs(round(n)-n) < eps))

prompt='Enter Integer:';

n=input(prompt);

else

error=false;

break;

end

end

error=true;

while error

if n==0

set=0;

error=false;

break;

else

if ~(n >0 and n<=5)

prompt='Another Guess:';

n=input(prompt);

error=true;

break;

else

error=false;

total=total+1;

out = randperm(m,l);

if out==n

userwin=userwin+1;

else

systemwin=systemwin+1;

end

system_plot(total)=systemwin;

user_plot(total)=userwin;

x=1:1:total;

plot(x,system_plot,'b+','LineWidth',1.1)

hold on

plot(x,user_plot,'rsquare','LineWidth',1.1)

plot(x,system_plot-user_plot,'_.g*','LineWidth',1.1)

hold off

legend('Times Computer Win','Times User win','Difference')

title('Figure1', 'FontSize',18);

end

end

end

end