Hi, I want to write a script which will prompt the user for minimum and maximum integers, and then another integer which is the user’s choice in the range from the minimum to the maximum. I then want the srcipt to generate random integers in the range from the minimum to the maximum until a match for the user’s choice is generated and print how many random integers had to be generated until a match for the user’s choice was found.
I am confused as to how to identify n, which is the number of iterations. Any suggestions would be greatly appreciated! This is my script so far:
function findmineimin=input('Please enter your minimum value: ');imax=input('Please enter your maximum value: ');choice=input('Now enter your choice in this range: ');% n=number of attempts
for i=1:n x(i)=randi([imin imax]); if x(i)==choice formatSpec='It took %d tries to get your number\n'; fprintf(formatSpec,n); else endendend
Best Answer