Small game with C language (2)-Scissors

Source: Internet
Author: User

Small game with C language (2)-Scissors

# Include <stdio. h> void menu () {printf ("************** welcome to the stone scissors cloth game ************* \ n "); printf ("********************* 1. start> ********************* \ n "); printf ("********************* 0. exit> ********************* \ n "); printf ("************************************* * ********* \ n ");} int main () {int input = 1; char ch [10]; int n = 0; int B = 0; int I = 0; int j = 0; int k = 0; int a = 0; while (input) {menu (); printf ("SELECT>"); scanf ("% d", & input ); switch (input) {case 1: {for (I = 0; I <3; I ++) {srand (unsigned int) time (NULL )); n = rand () % 3; printf ("extract stone-Scissors-cloth \ n"); scanf ("% s", ch); if (strcmp (ch, "Stone") = 0) B = 0; else if (strcmp (ch, "Scissors") = 0) B = 1; else if (strcmp (ch, "cloth") = 0) B = 2; if (B = n) {printf ("Draw \ n"); k ++ ;} else if (B = 0) & (n = 1) {printf ("Congratulations, you have won \ n"); j ++ ;} else if (B = 0) & (n = 2) {printf ("Sorry you lost \ n"); a ++ ;} else if (B = 1) & (n = 0) {printf ("Sorry you lost \ n"); a ++ ;} else if (B = 1) & (n = 2) {printf ("Congratulations, you have won \ n"); j ++ ;} else if (B = 2) & (n = 0) {printf ("Congratulations, you have won \ n"); j ++ ;} else {printf ("Sorry you lost \ n"); a ++;} if (j = 2) {break;} if (a = 2) {break ;}}if (j = 2) {printf ("Congratulations, you have won \ n"); break;} else if (a = 2) {printf ("Sorry you lost \ n"); break;} else if (k = 3) {printf ("this is a draw \ n "); break;} else if (k = 2) & (a = 1) {printf ("Sorry you lost in this game \ n "); break;} else if (k = 2) & (j = 1) {printf ("Congratulations, you have won \ n"); break ;} default: {printf ("exit GAME \ n"); system ("pause"); exit (0); break ;}} system ("pause "); return 0 ;}

 

Related Article

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.