Hi,
I have a script to simulate this classic game. The question is: How can I play many rounds? I was thinking that was using for loop, but I could not find the correct way to accomplish that.
Here the script without repetition:
disp('Stone, Paper and Scissors')disp('Stone (1)')disp('Paper (2)')disp('Scissors (3)')n=input('Which choice?: ')pc=[1,2,3];switch(n) case 1 MATChoice=datasample(pc,1) if c1==1 return end if MATChoice==2 display('MATLAB win; Player LOSE') return end if MATChoice==3 display('MATLAB lose; Player WIN') return end case 2 MATChoice=datasample(pc,1) if MATChoice==1 disp('MATLAB lose; Player WIN') return end if MATChoice==2 return end if MATChoice==3 disp('MATLAB win; Player LOSE') return end case 3 MATChoice=datasample(pc,1) if MATChoice==1 disp('MATLAB win; Player LOSE') return end if MATChoice==2 disp('MATLAB lose; Player WIN') return end if MATChoice==3 return end otherwise error('Choose 1,2 or 3') returnendreturnend
Could you help me, please?
Thank you.
Best Answer