Scissors expansion exercise, three innings and two wins

Source: Internet
Author: User

int count1 = 0, Count2 = 0;//Sets the number of wins, the number of losses

for (;;)

{

1. Prompt the user to punch

Console.Write ("Please Punch (stone 0, scissors 1, Cloth 2):");

int yh = Int. Parse (Console.ReadLine ());

2, computer randomly generated

Random r = new Random ();

int DN = R.next (0, 3);

3. Judging winning or losing

User wins: 0-1=-1 1-2=-1 2-0=2

The user loses: 0-2=-2 1-0=1 2-1=1

Draw 0

int JG = YH-DN;

if (YH < 0 | | YH > 2)

{

Console.WriteLine ("Wrong input! ");

}

Else

{

if (jg = =-1 | | jg = = 2)

{

Console.WriteLine ("You won!" ");

count1++;

if (count1 = = 2)

{

Console.WriteLine ("You finally won!") "); break;//win two results, jump out of the loop

}

}

else if (jg = =-2 | | jg = = 1)

{

Console.WriteLine ("You Lost!" ");

count2++;

if (Count2 = = 2)

{

Console.WriteLine ("You end up losing!") "); Break

}

}

else if (jg = = 0)

{

Console.WriteLine ("Draw! ");

}

}

}

Console.ReadLine ();

Scissors expansion exercise, three innings and two wins

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.