当前位置:网站首页>A lottery like scissors, stone and cloth (C language)
A lottery like scissors, stone and cloth (C language)
2022-07-03 09:52:00 【Embed it?】
A lottery 《 scissors 》(C Language )
Today we will introduce a game called :~~ scissors ~~ Oh !! cloth ……… He was actually drawn by lot .
A traditional scissors stone cloth , It looks something like this ——>
It's a judgment based on what happens to both sides , Who wins and who loses in a game .
But I don't think such a rule , In programming , Is it a little unfriendly to our programmers ?( Just a little bit of trouble ……)
So I came up with a simple method , To judge who wins and who loses .
Namely ,
* No Examination Consideration
What happens to players , It's numbers randomly given by the computer , To judge the victory 、 It's negative 、 It's a draw *
- 6、 ... and
Warm reminder : The header files of the following two functions are stdlib.h and time.h
adopt srand() Function and time() To produce a true random number
Re pass rand()%3, obtain 0、1、2 A certain number between
Then there is the use if sentence :
- if 0, Then the player wins ;
- if 1, Then the computer wins ;
- if 2, It's a draw ;
In this way, it looks like drawing lots ?
If you want to see your luck , Just copy the code and play a few games !
The code is as follows :
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int game();
void menu()
{
printf("#####################################\n");
printf("### ###\n");
printf("### 1、 Start 0、 sign out ###\n");
printf("### ###\n");
printf("#####################################\n");
}
int begin()
{
int x = 0;
printf(" type :1 or 0\n");
while(1)
{
printf(" Please select :");
scanf("%d",&x);
switch(x)
{
case 1:
printf("\n Successful entry into the game \n");
game();
printf("\n The game is over .\n 1 or 0\n");
break;
case 0:
printf(" Quit the game \n");
goto Loop;
break;
default:
printf(" Input format error , Please re-enter !\n");
break;
}
}
Loop:
return 0;
}
int game()
{
int ps = 0;
// Players and computers play tricks
int cop = rand()%3;//cop ~~ [0,2]
printf("\n The player :\n\n stone :0\n scissors :1\n cloth :2\n Please select :");
scanf("%d",&ps);
// Player stage
if(ps==0)
{
printf("\n Player out : stone \n");
}
else if(ps==1)
{
printf("\n Player out : scissors \n");
}
else if(ps==2)
{
printf("\n Player out : cloth \n");
}
// Computer phase + Judgment stage
if(cop==0)// When cop==0 when , Computer input .
{
if(ps==0)
{
printf(" Computer out : scissors \n");
}
else if(ps==1)
{
printf(" Computer out : cloth \n");
}
else if(ps==2)
{
printf(" Computer out : stone \n");
}
printf("\n The player wins !!\n");
}
else if(cop==1) // When cop==1 when , Computers win .
{
if(ps==0)
{
printf(" Computer out : cloth \n");
}
else if(ps==1)
{
printf(" Computer out : stone \n");
}
else if(ps==2)
{
printf(" Computer out : scissors \n");
}
printf("\n The computer wins !!\n");
}
else if(cop==2) // When cop==2 when , It ends in a draw .
{
if(ps==0)
{
printf(" Computer out : stone \n");
}
else if(ps==1)
{
printf(" Computer out : scissors \n");
}
else if(ps==2)
{
printf(" Computer out : cloth \n");
}
printf("\n It ends in a draw ……\n");
}
return 0;
}
int main()
{
srand((unsigned)time(NULL));//unsigned >= 0
menu();
begin();
return 0;
}
The above is purely Mengxin's speech , Don't be surprised to see the boss , Don't laugh .
边栏推荐
- UCI and data multiplexing are transmitted on Pusch (Part V) -- polar coding
- SCM career development: those who can continue to do it have become great people. If they can't endure it, they will resign or change their careers
- Global KYC service provider advance AI in vivo detection products have passed ISO international safety certification, and the product capability has reached a new level
- Nr-prach:prach format and time-frequency domain
- Leetcode daily question (2212. maximum points in an archery competition)
- [graduation successful] [1] - tour [Student Management Information System]
- Desktop icon recognition based on OpenCV
- Convert IP address to int
- Fundamentals of Electronic Technology (III)__ Chapter 6 combinational logic circuit
- Project cost management__ Plan value_ Earned value_ Relationship among actual cost and Countermeasures
猜你喜欢

UCI and data multiplexing are transmitted on Pusch - placement of data and UCI positions (Part III)

The third paper of information system project manager in soft examination
![[CSDN]C1訓練題解析_第三部分_JS基礎](/img/b2/68d53ad09688f7fc922ac65e104f15.png)
[CSDN]C1訓練題解析_第三部分_JS基礎

Comment la base de données mémoire joue - t - elle l'avantage de la mémoire?

学习开发没有捷径,也几乎不存在带路会学的快一些的情况
![Successful graduation [3]- blog system update...](/img/91/72cdea3eb3f61315595330d2c9016d.png)
Successful graduation [3]- blog system update...

Leetcode daily question (1162. as far from land as possible)

Nodemcu-esp8266 development (vscode+platformio+arduino framework): Part 3 --blinker_ MIOT_ Light (lighting technology app control + Xiaoai classmate control)

CEF download, compile project

Leetcode daily question (2212. maximum points in an archery competition)
随机推荐
我想各位朋友都应该知道学习的基本规律就是:从易到难
Difference of EOF
PRACH --- originator
应用最广泛的8位单片机当然也是初学者们最容易上手学习的单片机
Happy Dragon Boat Festival—— Zongzi written by canvas~~~~~
Introduction to chromium embedded framework (CEF)
Jestson nano downloads updated kernel and DTB from TFTP server
Stm32-hal library learning, using cubemx to generate program framework
STM32 external interrupt experiment
单片机现在可谓是铺天盖地,种类繁多,让开发者们应接不暇
Design and development of biological instruments
Install local sources using yum
The third paper of information system project manager in soft examination
Nodemcu-esp8266 development (vscode+platformio+arduino framework): Part 5 --blinker_ MIOT_ MULTI_ Outside (lighting technology app + Xiaoai classmate control socket multiple jacks)
Solve editor MD uploads pictures and cannot get the picture address
numpy. Reshape() and resize() functions
Leetcode daily question (1856. maximum subarray min product)
Project cost management__ Cost management technology__ Article 8 performance review
[combinatorics] Introduction to Combinatorics (combinatorial thought 2: mathematical induction | mathematical induction promotion | multiple induction thought)
QT qcombobox QSS style settings