Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

rock paper scissors c#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Do you choose rock,paper or scissors");
            string userChoice = Console.ReadLine();

            Random r = new Random();
            int computerChoice = r.Next(4);

                if (computerChoice == 1)
                {
                    if (userChoice == "rock")
                    {
                        Console.WriteLine("The computer chose rock");
                        Console.WriteLine("It is a tie ");                     
                    }
                    else if (userChoice == "paper")
                    {
                        Console.WriteLine("The computer chose paper");
                        Console.WriteLine("It is a tie ");

                    }
                    else if (userChoice == "scissors")
                    {
                        Console.WriteLine("The computer chose scissors");
                        Console.WriteLine("It is a tie ");
                    }
                    else
                    {
                        Console.WriteLine("You must choose rock,paper or scissors!");

                    }

                }

                else if (computerChoice == 2)
                {
                    if (userChoice == "rock")
                    {
                        Console.WriteLine("The computer chose paper");
                        Console.WriteLine("Sorry you lose,paper beat rock");

                    }
                    else if (userChoice == "paper")
                    {
                        Console.WriteLine("The computer chose scissors");
                        Console.WriteLine("Sorry you lose,scissors beat paper ");

                    }
                    else if (userChoice == "scissors")
                    {
                        Console.WriteLine("The computer chose rock");
                        Console.WriteLine("Sorry you lose,rock beats scissors");                       
                    }
                    else
                    {
                        Console.WriteLine("You must choose rock,paper or scissors!");        
                    }
                }
                else if (computerChoice == 3)
                {
                    if (userChoice == "rock")
                    {
                        Console.WriteLine("The computer chose scissors");
                        Console.WriteLine("You win,rock beats scissors");

                    }
                    else if (userChoice == "paper")
                    {
                        Console.WriteLine("The computer chose rock");
                        Console.WriteLine("You win,paper beats rock");

                    }
                    else if (userChoice == "scissors")
                    {
                        Console.WriteLine("The computer chose paper");
                        Console.WriteLine("You win,scissors beat paper");

                    }
                    else
                    {
                        Console.WriteLine("You must choose rock,paper or scissors!");

                    }

                }

            Console.ReadLine();
        }
    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: ef rollback migration 
Csharp :: split string on last element 
Csharp :: weapon switching unity 
Csharp :: raylib c# 
Csharp :: unity audio 
Csharp :: c# list object sort alphabetically 
Csharp :: how to rotate object in unity only on one axis 
Csharp :: c# getting user input 
Csharp :: recursive reverse linked list 
Csharp :: get sha1 of file c# 
Csharp :: unity deactivate component 
Csharp :: how to save a dictionary as a csv file in c# 
Csharp :: Entity Framework Core 3.1 Return value (int) from stored procedure 
Csharp :: creating a streamwiter file C# 
Csharp :: NameValueCollection 
Csharp :: asp.net model 
Csharp :: c# how to check if a array bool is all true 
Csharp :: on collision enter by layer 2d unity 
Csharp :: c# return 2 values 
Csharp :: How to make game object transparent in unity 
Csharp :: c# video to frames 
Csharp :: c# check if char is string 
Csharp :: verify if number c# 
Csharp :: how to create public variable in c# 
Csharp :: how to create a variable in c# 
Csharp :: ef core include 
Csharp :: multidimensional arrays c# 
Csharp :: if c# 
Csharp :: entity framework core genetare class using existing database 
Csharp :: how to remove all comma from string c# 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =