Determining the winner of rock paper scissors?

In this program I am attempting to determine the winner of rock, paper, scissors. unfortunately when using lowercase letters the code will register it as an invalid entry. How could I get around this?

I thought that converting the characters to upper case would help?

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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
  int main()
{
    	// Declare variables
	char playerOne = ' ' ;
    	char playerTwo = ' ';
    	char letter= ' ';
		
		// request input
    		cout << "player 1:Enter r for rock, p for paper or s for scissors: ";
    		cin >> playerOne;
    
    		cout << "player 2:Enter r for rock, p for paper or s for scissors: ";
    		cin >> playerTwo;
    		
    	// convert character to uppercase
         letter = toupper(letter);
         letter = toupper(letter);
         letter = toupper(letter);
		// Determine game	
    	if (playerOne == 'R')
    	{
        
        		if (playerTwo == 'P')
        		{
            		cout << "player 2 has won the game." << endl;
        
        		}
        		if (playerTwo == 'R')
        		{
            		cout << "Tie." << endl;
            		
        		}
        		if (playerTwo == 'S')
        		{
            		cout << "player 1 has won the game." << endl;
            		
        		}
        		

    	}
    	if (playerOne == 'P')
    	{
              
        		if (playerTwo == 'S')
        		{
            		cout << "player 2 has won the game." << endl;
        
        		}
        		if (playerTwo == 'P')
        		{
            		cout << "Tie." << endl;
            		
        		}
        		if (playerTwo == 'R')
        		{
            		cout << "player 1 has won the game." << endl;
            		
        		}
    	}
    	if (playerOne == 'S')
    	{
              
        		if (playerTwo == 'R')
        		{
            		cout << "player 2 has won the game." << endl;
        
        		}
        		if (playerTwo == 'S')
        		{
            		cout << "Tie." << endl;
            		
        		}
        		if (playerTwo == 'P')
        		{
            		cout << "player 1 has won the game." << endl;
            		
        		}
    	}
    
		else if (playerOne != 'R' && playerOne != 'P' && playerOne != 'S')
    	{
                  
      	cout << "Game canceled because of invalid entry." << endl;
      
    	}
		
		else if (playerTwo != 'R' && playerTwo != 'P' && playerTwo != 'S')
    	{
                  
      	cout << "Game canceled because of invalid entry." << endl;
      
    	}
		
    	system("pause");
    	return 0;
}


Thanks!
The error is at line number 16-18.
It should be:
1
2
3
        playerOne= toupper(playerOne);
        playerTwo= toupper(playerTwo);
Last edited on
Ah, Thanks! I guess I need to stop trying to do stuff that early in the morning.
Topic archived. No new replies allowed.