Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- #include <time.h>
- int main(void)
- {
- int choice;
- int R=1, P=2, S=3;
- int Pscore=0;
- int Cscore=0;
- int i=0;
- srand(time(NULL));
- printf("Play Rock, Paper, Scissors against a computer.\n");
- printf("Enter 1 for Rock, 2 for Paper, or 3 for Scissors.");
- scanf("%d", &choice);
- while (i<7)
- {
- int computer=rand()%3+1;
- i++;
- switch (choice)
- {
- case 1:
- if (Cscore > 4 || Pscore > 4)
- {
- break;
- }
- if (computer==1)
- {
- printf("The computer's choice was:%d\n", computer);
- printf("DRAW.\n");
- printf("Enter another choice:\n");
- scanf("%d", &choice);
- }
- else if (computer==2)
- {
- printf("The computer's choice was:%d\n", computer);
- printf("Computer Wins.\n");
- printf("Enter another choice:\n");
- scanf("%d", &choice);
- Cscore= Cscore+1;
- }
- else if (computer==3)
- {
- printf("The computer's choice was:%d\n", computer);
- printf("You win!\n");
- printf("Enter another choice:\n");
- scanf("%d", &choice);
- Pscore= Pscore+1;
- }
- break;
- case 2:
- if (Cscore > 4 || Pscore > 4)
- {
- break;
- }
- if (computer==2)
- {
- printf("The computer's choice was:%d\n", computer);
- printf("DRAW.\n");
- printf("Enter another choice:\n");
- scanf("%d", &choice);
- }
- else if (computer==1)
- {
- printf("The computer's choice was:%d\n", computer);
- printf("Computer Wins.\n");
- Cscore= Cscore+1;
- printf("Enter another choice:\n");
- scanf("%d", &choice);
- }
- else if (computer==3)
- {
- printf("The computer's choice was:%d\n", computer);
- printf("You win!\n");
- Pscore= Pscore+1;
- printf("Enter another choice:\n");
- scanf("%d", &choice);
- }
- break;
- case 3:
- if (Cscore > 4 || Pscore > 4)
- {
- break;
- }
- if (computer==3)
- {
- printf("The computer's choice was:%d\n", computer);
- printf("DRAW.\n");
- printf("Enter another choice:\n");
- scanf("%d", &choice);
- }
- else if (computer==1)
- {
- printf("The computer's choice was:%d\n", computer);
- printf("Computer Wins.\n");
- Cscore= Cscore+1;
- printf("Enter another choice:\n");
- scanf("%d", &choice);
- }
- else if (computer==2)
- {
- printf("The computer's choice was:%d\n", computer);
- printf("You win!\n");
- Pscore= Pscore+1;
- printf("Enter another choice:\n");
- scanf("%d", &choice);
- }
- default:
- printf("Invalid Input\n");
- system("clr");
- }
- }
- if (Cscore > Pscore || Cscore > 4 )
- {
- printf("Computer has won the matches.\n");
- }
- else if (Cscore < Pscore || Pscore > 4)
- {
- printf("You won the matches!\n");
- }
- else if (Cscore == Pscore && Cscore != 0 && Pscore !=0)
- {
- printf("It's a DRAW!\n");
- }
- else
- {
- printf("Sorry, You have entered the wrong number.");
- }
- printf("Program will now clear the screen if you press any key.");
- getch();
- system("cls");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement