From c6eab7534c06756c2c00b8a1e886a71cf4f61319 Mon Sep 17 00:00:00 2001 From: Jatin Ranpariya <72184476+jatin1510@users.noreply.github.com> Date: Thu, 1 Oct 2020 11:46:36 +0530 Subject: [PATCH] Create Stone Paper Scissor game by C language --- Stone Paper Scissor game by C language | 113 +++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 Stone Paper Scissor game by C language diff --git a/Stone Paper Scissor game by C language b/Stone Paper Scissor game by C language new file mode 100644 index 0000000..6af0c8a --- /dev/null +++ b/Stone Paper Scissor game by C language @@ -0,0 +1,113 @@ +#### for creating this game in C programming , You have to write code as shown below + +#include +#include +#include +int Random(int n) +{ + srand(time(NULL)); //srand takes seed as an input and is defined inside + return rand() % n; +} +// Create Rock, paper & Scissors Game +// player 1 : rock +// player 2 (computer) : scissors--> player 1 gets 1 point + +// stone(0) vs scissors(2) - stone(0) wins +// paper(1) vs stone(0) - paper(1) wins +// scissors(2) vs paper(1) - scissors(2) wins + +// write a C program to allow user to play this game three times with computer. Log the scores of computer and the player.Display the name of the winner at the end. + +// Notes : You have to display name of the player during the game , Take users name as an input from the user. + +int main() +{ + // printf("The random number between 0 to 2 is %d\n", Random(3)); + printf("Welcome !!! Enter your name : "); + char name[50]; + gets(name); + int i = 0; + int p = 0, c = 0; + + printf("You're welcome %s , in Stone-paper-scissors game.\n", name); + printf("Hey,\npress 0 for stone.\npress 1 for paper.\npress 2 for scissors.\n\n"); + while (i < 3) + { + + printf("%s's turn : ", name); + int n; + scanf("%d", &n); + printf("Computer's Turn : %d\n\n", Random(3)); + if (n == 0) + { + if (Random(3) == 0) + { + goto end; + } + else if (Random(3) == 1) + { + c++; + } + else + { + p++; + } + } + + if (n == 1) + { + if (Random(3) == 0) + { + p++; + } + else if (Random(3) == 1) + { + goto end; + } + else + { + c++; + } + } + + if (n == 2) + { + if (Random(3) == 0) + { + c++; + } + else if (Random(3) == 1) + { + p++; + } + else + { + goto end; + } + } + + end: + i++; + } + printf("\n"); + printf("~~~~~~~~~~score~~~~~~~~~~ \n"); + printf("%s : computer = %d : %d\n", name, p, c); + if (p == c) + { + printf("The match is tied.\n"); + } + else if (p >> c) + { + printf("congratulations,%s\nyou won the game against computer.\n", name); + } + else + { + printf("You lose...\nPLEASE...!!! TRY AGAIN\n"); + } + printf("~~~~~~~~~~score~~~~~~~~~~ \n"); + + + return 0; +} + +#### BEST OF LUCK