How do I get my won/loss/tie counter to work?

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
101
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <string>
using namespace std;

int main(void)
{
	bool looping = true;
	
  while (looping == true)
  {
  	
      srand(time(NULL));
      
    int win = 0;
    int loss = 0;
    int tie = 0;
    int randnum = rand() %3;
    string userchoice;
    string computerchoice;

    cout << "\nWelcome to rock, paper, scissors!\n";
    cout << "rock, paper, or scissors?\n";
    cin >> userchoice;


    if (randnum == 1)
    {
        computerchoice = "rock";
    } 
    else if (randnum == 2) 
    {
        computerchoice = "paper";
    } 
    else 
    {
         computerchoice = "scissors";
    }

    cout << computerchoice << " \n";

    if (userchoice == "rock" && computerchoice == "rock")
    {
    	cout << "its a tie!";
    	tie++;
    }
    else if (userchoice == "scissors" && computerchoice == "scissors")
    {
    	cout << "its a tie!";
    	tie++;
    }
    else if (userchoice == "paper" && computerchoice == "paper")
    {
	    cout << "its a tie!";
	    tie++;
    }
    else if (userchoice == "rock" && computerchoice == "scissors")
    {
    	cout << "you win!";
    	win++;
    }
    else if (userchoice == "rock" && computerchoice == "paper")
    {
	    cout << "better luck next time";
	    loss++;
    } 
    else if (userchoice == "scissors" && computerchoice == "rock")
    {
    	cout << "better luck next time";
    	loss++;
    }
    else if (userchoice == "scissors" && computerchoice ==  "paper")
    {
    	cout << "you win";
    	win++;
    }
    else if (userchoice == "paper" && computerchoice == "rock")
    {
    	cout << "you win";
    	win++;
    }
    else if (userchoice == "paper" && computerchoice == "scissors")
    {
    	cout << "better luck next time";
    	loss++;
    }
    else if (userchoice == "quit")
    {
    	looping = false;
    	cout << "your wins " << win << "\n";
    	cout << "your losses " << loss << "\n";
    	cout << "your ties " << tie << "\n";
    }
    else
    {
    	cout << "what is wrong with you?";
    }
  }
    return 0;
}
These lines:
1
2
3
4
5
      srand(time(NULL));
      
    int win = 0;
    int loss = 0;
    int tie = 0;

Move them outside of (before) the while loop, just like how your looping variable is made.

srand only needs to be seeded once, at the beginning of the program.
Last edited on
Thank you
Topic archived. No new replies allowed.