RockPaperScissors

Pages: 12
Right - don' t need lines 6 - 12 at all!

You will need to declare userint (translates char to int ) as int before your switch/case, too.

You are getting very close to a working program here!

There are some things I would do differently, but they might depend on using techniques you aren't familiar with. I've been trying to get a feel for what you do understand so I can make suggestions that aren't out-of-bounds for you. In the long run, don't worry - you'll be thinking in computerese soon enough!

Last edited on
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
97
98
99
100
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <cstdio>
#include <time.h>
#include <map>

using namespace std;

int main()
{
    	unsigned seed;
    	int comp;
        int draw=0;
        int score=0;                               // users score
        int score2=0;                              // computers score
        int userint=0;                   
        
        
        
  
int c = ' ' ;
while ( c != 'a' && c != EOF ) {

 

cout << "enter \"rock\", \"paper\", or \"scissors\" (a to exit) \n";

string s;

if (cin>>s) {

 srand (time(NULL)); 
 
  comp = rand() % 3 + 1; 


map<int,string>map {	

  { 1, "paper" },
  { 2, "scissors" },
  { 3, "rock" },

 };


bool draw = false;    
bool win = false; 
 

switch (s[0])
{
case 'r':  win = (comp == 2) ; userint=1;  break;         
            
case 'p':  win = (comp == 3);  userint=2;  break;

case 's':  win = (comp == 1);  userint=3;   break;

}


if (userint == comp)   { bool draw=true;}
   
  

cout << "Player chooses " << s << endl;
cout << "Computer chooses " << map[comp] << endl;


if (win) { cout << "You Won!";
            		score ++; }

else if (draw)

          { cout << "Tied!";
            		draw ++; }

else  { cout << "You lost!";
            		score2 ++; }



cout << " score: you==" << score << " computer==" << score2 << " same==" << draw << "\n";



 cout << "enter a to quit or hit enter to continue.\n" ;
        cin.clear() ; 
        cin.ignore( 1000, '\n' ) ; 
        c = cin.get() ;
   }

   

  }

      cout << " See you later PCrumley48! ";
} 
      
                       


Topic archived. No new replies allowed.
Pages: 12