1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
#include <stdio.h>
//Prototypes
void displayRules();
int validSelection(char selection);
int playResult(char play1, char play2, int count1, int count2);
void displayResults(int pCount, int wCount1, int wCount2);
//Main
int main()
{
//playerChoice 1 = Player 1's Decision
//playerChoice 2 = Player 2's Decision
//decision = Choice To Play Again
//count = Round Count
//p1count, p2count = Winning Count For Each Player
//inCheck1, inCheck2 = Input Check For Each Player
char playerChoice1, playerChoice2, decison;
int count = 0, p1count = 0, p2count = 0, inCheck1, inCheck2;
//Displays The Rules
displayRules();
//Asks For User Choices
printf("Player 1 enter your choice: ");
scanf("%c", &playerChoice1);
getchar();
inCheck1 = validSelection(playerChoice1);
if(inCheck1 == 0)
{
printf("You Haven't Used Rock, Paper, Or Scissor, Please Try Again\n");
scanf("%c", playerChoice1);
inCheck1 = validSelection(playerChoice1);
}
printf("Player 2 enter your choice: ");
scanf("%c", &playerChoice2);
getchar();
inCheck2 = validSelection(playerChoice2);
if(inCheck2 == 0)
{
printf("You Haven't Used Rock, Paper, or Scissor, Please Try Again\n");
scanf("%c", playerChoice2);
inCheck2 = validSelection(playerChoice2);
}
//Validates Input
inCheck2 = validSelection(playerChoice2);
system("pause");
}
void displayRules()
{
printf("Welcome to the game of Rock, Paper, Scissors.\n\n");
printf("This is a game for two players. For each game, \n");
printf("each player selects one of the objects, Rock, Paper, or Scissors.\n\n");
printf("The rules for winning the game are: \n\n");
printf("1. If both players select the same object, it is a tie.\n\n");
printf("2. Rock beats Scissors. \n\n");
printf("3. Paper beats Rock. \n\n");
printf("4. Scissors beats Paper.\n\n");
printf("Enter R to select Rock, P to select Paper, and S to select Scissors.\n");
}
int validSelection(char selection)
{
if(selection == 'r' || selection == 'R' || selection == 'p' || selection == 'P' || selection == 's' || selection == 'S')
return 1;
else if(selection != 'r' || selection != 'R' || selection != 'p' || selection != 'P' || selection != 's' || selection != 'S')
return 0;
}
|