gistlib
main.m% Rock Paper Scissors Game against Computer % Display options disp('Welcome to Rock Paper Scissors Game!'); disp('1 - Rock'); disp('2 - Paper'); disp('3 - Scissors'); % Get user's choice userChoice = input('Enter your choice (1, 2, or 3): '); % Computer's choice computerChoice = randi([1, 3]); % Determine winner if userChoice == computerChoice disp('It is a tie!'); elseif (userChoice == 1 && computerChoice == 3) || ... (userChoice == 2 && computerChoice == 1) || ... (userChoice == 3 && computerChoice == 2) disp('You win!'); else disp('Computer wins!'); end % Display choices disp(['Your choice: ' num2str(userChoice)]); disp(['Computer choice: ' num2str(computerChoice)]); 710 chars29 lines
% Rock Paper Scissors Game against Computer % Display options disp('Welcome to Rock Paper Scissors Game!'); disp('1 - Rock'); disp('2 - Paper'); disp('3 - Scissors'); % Get user's choice userChoice = input('Enter your choice (1, 2, or 3): '); % Computer's choice computerChoice = randi([1, 3]); % Determine winner if userChoice == computerChoice disp('It is a tie!'); elseif (userChoice == 1 && computerChoice == 3) || ... (userChoice == 2 && computerChoice == 1) || ... (userChoice == 3 && computerChoice == 2) disp('You win!'); else disp('Computer wins!'); end % Display choices disp(['Your choice: ' num2str(userChoice)]); disp(['Computer choice: ' num2str(computerChoice)]);
gistlibby LogSnag