In the game of scissors, paper, stone (or Jack N Poy or Pick) each of two players choose either scissors (code X),paper (code P) or stone (code S). If one chooses scissors and the other chooses stone then paper wins. If one chooses paper and the other scissors then scissors wins. If they both chooses the same then the result is tie. Read in two character codes corresponding to the object selected and then output either message ‘PLAYER 1 WINS’, ‘PLAYER 2 WINS’ or ‘TIE’. Use the output format below:
JACK N POY GAME
PLAYER 1 ENTER :<value and not code>
PLAYER 2 ENTER:<value and not code>
RESULT :<result>
1
Expert's answer
2012-07-26T08:53:36-0400
using System; using System.Collections.Generic; using System.Linq; using System.Text;
namespace ConsoleApplication1 { class Program { & static void Main(string[] args) & { string again; do { Console.WriteLine("Enter symbol for first player (scissors (code X),paper (code P) or stone (code S)):"); string player1, player2; player1 = Console.ReadLine(); Console.WriteLine("Enter symbol for second player (scissors (code X),paper (code P) or stone (code S)):"); player2 = Console.ReadLine(); if (player2 == player1) { & Console.WriteLine("TIE"); } else if ((player1 == "S" || player1 == "s") && (player2 == "X" || player2 == "x") || & (player1 == "X" || player1 == "x") && (player2 == "P" || player2 == "p") || & (player1 == "P" || player1 == "p") && (player2 == "S" || player2 == "s")) { & Console.WriteLine("player number one win!"); } else { & Console.WriteLine("player number two win!"); } Console.WriteLine("Do you want play again? enter Y"); again = Console.ReadLine(); } while (again == "Y" || again == "y");
Comments
Leave a comment