Rock Paper Scissors in regular C

So everything seems to be working fine except when it gets to 'player2' input it just skips it and procedes to print everything under all the If statements.

What am I missing here??

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
// Rock_Paper_Scissors.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdio.h>


int _tmain(int argc, _TCHAR* argv[])
{
	char choice, player1, player2;
	do
	{
	printf("Welcome to Rock - Papper - Scissors.\n");
	printf("PLAYER 1\nPlease enter:\nR for Rock\nP for Papper\nS for Scissors\n");
	scanf("%c", &player1);

	printf("PLAYER 2\nPlease enter:\nR for Rock\nP for Papper\nS for Scissors\n");
	scanf("%c", &player2);

	//Ties!!!
	if (((player1 == 'r') || (player1 == 'R')) && ((player2 == 'r') || player2 == 'R'));
	{
	printf("TIE!!!");
	}
	if (((player1 == 'p') || (player1 == 'P')) && ((player2 == 'p') || player2 == 'P'));
	{
	printf("TIE!!!");
	}
	if (((player1 == 's') || (player1 == 'S')) && ((player2 == 's') || player2 == 'S'));
	{
	printf("TIE!!!");
	}
	//Player 1 Wins!!!
	if (((player1 == 'r') || (player1 == 'R')) && ((player2 == 's') || player2 == 'S'));
	{
	printf("Player 1 Wins!!!");
	}
	if (((player1 == 's') || (player1 == 'S')) && ((player2 == 'p') || player2 == 'P'));
	{
	printf("Player 1 Wins!!!");
	}
	if (((player1 == 'p') || (player1 == 'P')) && ((player2 == 'r') || player2 == 'R'));
	{
	printf("Player 1 Wins!!!");
	}
	//Player 2 Wins!!!
	if (((player2 == 'r') || (player2 == 'R')) && ((player1 == 's') || player1 == 'S'));
	{
	printf("Player 2 Wins!!!");
	}
	if (((player2 == 's') || (player2 == 'S')) && ((player1 == 'p') || player1 == 'P'));
	{
	printf("Player 2 Wins!!!");
	}
	if (((player2 == 'p') || (player2 == 'P')) && ((player1 == 'r') || player1 == 'R'));
	{
	printf("Player 2 Wins!!!");
	}
	//Loop
	printf("Would you like to play again?\nPlease enter:\nY for Yes\nN for NO");
	scanf("%c", &choice);
	if(choice == 'N' || choice == 'n')
	{
	printf("Good Bye!\n");
	break;
	} 
	}while(choice != 'N' || choice != 'n');

		return 0;
}
Anyhelp at all would be appreciated
You really shouldn't use scanf or its siblings. If there's one you learn about scanf is it should not be used.

When the program stops at the first prompt and you type: R<ENTER>, it reads R into player1 and <ENTER> into player2.

Try using gets() instead, it's more intuitive.
Last edited on
or you could change your scanf format strings to " %c" so that they eat whitespace (spaces/tabs/newlines) before they try to read in input.

gets() is less safe than scanf.
Topic archived. No new replies allowed.