Using vc++6.0 to realize the program _c language of stone scissors cloth game

Source: Internet
Author: User
Tags rand strcmp

The source program is seen from the Internet,
Geek_monkey modified the bug on March 3, 2015 (input word Fu Fei stone scissors cloth is the player wins)
Compilation environment is vc++6.0
Adding "God Mode" and data statistics is purely entertaining.
I am a C language beginner, lightly sprayed

Copy Code code as follows:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
int exist_in (char *arr1[][2], char *arr2[], int length);
void Nextround (void);//the processing wheel function after the end of this round
enum {Quit,ok} status;//flag bit, quit=0,ok=1
int vcnt = 0,dcnt = 0,tcnt = 0;//Data statistics
int main (void)
{
int i = 0, length;
time_t T;
status = OK;
Char *person = (char *) malloc (100);//Dynamic memory allocation
Char *computer = (char *) malloc (100);
Char *computer_person[2];
Char *guess_arr[] = {"Stone", "scissors", "cloth"};
Char *win[3][2] = {"Cloth", "stone"}, {"Stone", "scissors"}, {"Scissors", "Cloth"}};
length = (int) sizeof (WIN)/(int) sizeof (win[0]);//In this case length=3
while (status = = OK)//Flag bit 1, perform a dead loop
{
Srand ((unsigned) time (&t));
i = rand ()% 3;//srand and Rand cooperate to produce random numbers
Computer = guess_arr[i];//Converts a random number to a string of stone scissors or cloth
Computer_person[0] = computer;//puts the computer's punch result into *computer_person
do{
printf ("Please input scissors stone cloth: \ n");
scanf ("%s", person);
if (strcmp (person, "god") = = 0)//God mode, realize can see the computer out fist result
{
printf ("*********************************\n");
printf ("Hello God, computer this council out is:%s \ n", computer);
printf ("*********************************\n");
Continue
}
Else
printf ("You enter:%s\n", person);//The next line is used to determine if the user's input is a stone scissors cloth
if (strcmp (person, "stone") = = 0) | | (strcmp (Person, "scissors") = = 0) | | (strcmp (person, "cloth") = = 0))
break;//results for one of the stone scissors, which jumps out of circulation.
Else
printf ("Please check if your input is stone scissors or cloth: \ n");
}while (1);
COMPUTER_PERSON[1] = person;
tcnt++;
if (strcmp (computer, person) = 0)
{
printf ("Deuce!") \ n ');
}
else if (exist_in (Win, Computer_person, length)
{
printf ("computer wins \ n \ nthe");
dcnt++;
}
Else
{
printf ("player wins \ n \ nplease");
vcnt++;
Nextround ();
}
}
person = NULL;
computer = NULL;
Free (person);
Free (computer);
return 0;
}
/**********************************************
The exist_in function is used to determine whether the computer wins, length 3, 3 times, arr1 and arr2 string
Order to determine whether the computer wins.
*********************************************/
int exist_in (char *arr1[][2], char *arr2[], int length)
{
int i;
for (i = 0; i < length; i++)
{
if (strcmp (arr1[i][0], arr2[0]) = = 0 && strcmp (arr1[i][1], arr2[1]) = = 0)
{
return 1;
}
}
return 0;
}
void Nextround (void)
{
int m = 0;
printf ("Please enter directive: 1 exit, 2 continue, 3 data summary \ n");
scanf ("%d", &m);
Switch (m)
{
Case 1:
status = QUIT;
Break
Case 2:
printf ("The new bureau begins \ n");
Break
Case 3:
printf ("Your number of WINS is%d, the number of defeats is%d, the total number of fields is%d\n", vcnt,dcnt,tcnt);
status = QUIT;
Break
Default
printf ("Input error Exits");
status = QUIT;
Break
}
}

The above is to use VC + + to achieve the stone scissors Cloth Program of all the code, I hope to learn VC + + can help.

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.