Last active
August 29, 2019 12:44
-
-
Save BMuscle/cc4ca930896bbe60bd72c66fc5374732 to your computer and use it in GitHub Desktop.
じゃんけんソース⑤
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| int jankenJudge(int p1, int p2){//プレイヤーの手を引数に | |
| int judge;//返す為のjudgeを宣言 | |
| //勝ち負けの判定 | |
| if(p1 == p2){ | |
| judge = 3;//あいこの場合 | |
| }else{ | |
| p1 = p1 % 3;//相手との差を求める | |
| if(p1 + 1 == p2){ | |
| judge = 1;//P1が勝ち | |
| }else{ | |
| judge = 2;//あいこは条件から外れているのでP2の勝ち | |
| } | |
| } | |
| return judge; | |
| } | |
| void result(int judge){//求められたjudgeを使う | |
| //結果の出力 | |
| switch(judge){ | |
| case 1://プレイヤー1の勝ち | |
| printf("プレイヤー1の勝ち!!\n"); | |
| break; | |
| case 2://プレイヤー2の勝ち | |
| printf("プレイヤー2の勝ち!!\n"); | |
| break; | |
| case 3://あいこ | |
| printf("あいこです\n"); | |
| break; | |
| default: | |
| break; | |
| } | |
| } | |
| int main(void){ | |
| int player1;//プレイヤー1の手 | |
| int player2;//プレイヤー2の手 | |
| int judge; | |
| scanf("%d", &player1);//プレイヤー1の手を格納 | |
| scanf("%d", &player2);//プレイヤー2の手を格納 | |
| judge = jankenJudge(player1, player2);//じゃんけんの判定 | |
| result(judge);//結果の出力 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment