Something is wrong with my rands's?

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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#include <iostream>
#include <cstdlib>
using namespace std;

class Dice{
                //Constructor
        public:
                Dice();
                Dice(int);      
                double score();
                double randPoints;      
                
                int pointTotal, a;

                double getRolls();
                void setRolls(double&,double&);

                
                
                
//methods       
                int roll();
                void resetNumRolls();
                int getNumRolls();              
                int playerPoints();
                int compPoints();
                int pointsTotal();
                int computerTotal();
                        
        private:
                //properties
                int numRolls;
                int numSides;   
                int numPoints;
                int rollTotal;
                double rolls;   
                

        
};


/*****************************************************
        Paramerterized constructor
        set the number of sides when created
        @param sides is the number of sides for this die
        ***************************************************/

Dice::Dice(int sides){
        numSides=6;
        numRolls=0;
        numPoints=50;
        
        //initialize random # generator
        srand(time(NULL));
}


/******************************************************
        Default Constructor. Creates a die with 6 sides
        ***************************************************/
        
Dice::Dice(){
        numSides=6;
        numRolls=0;
        numPoints=50;
        
        
        //initialize random # generator
        srand(time(NULL));
}

/*************************************************
*"Rolls" the dice
*@return a number between [1, numSides]
*************************************************/
int Dice::roll(){
        //generate a number between 1 - numSides
        int rollVal = (rand() % numSides) + 1;
        return rollVal;

}

int Dice::playerPoints(){
        int randPoints = (rand() % numPoints) ;
        return randPoints;
        }
        

int Dice::compPoints(){
        int randPoints = (rand() % numPoints) + 10;
        return randPoints;
        
}

int Dice::pointsTotal(){
        int x = 0;
        int total = x+playerPoints();
        return total;

}
/*void Dice::setRolls(double& rolls, double& points){
int b;
rolls=1+b;


                
}
*/
double Dice::getRolls(){
        return(rolls);
}



        


/*******************************************
        Gives the user the number of rolls
**********************system("color fc")*********************/

int Dice::getNumRolls(){
        return numRolls;
}

/*******************************************
        Reset the number of rolls to 0
        ****************************************/
void Dice::resetNumRolls(){
        numRolls = 0;   
}

int main(){
        Dice playerOne;
        Dice playerTwo; 
        
        cout<<"********************************"<<endl;       
        cout<<"**********************************"<<endl;
        cout<<"******Semantic Troubles***********"<<endl;
        cout<<"********...wait what?*************"<<endl;
        cout<<"**********************************"<<endl;
        cout<<"**********************************"<<endl;
        
        cout<<"The rules of this game are simple,"<<endl;
        cout<<"Erm...Did you say something?"<<endl;
        cout<<"Okay yes, There are 20 possible spots"<<endl;
        cout<<"on this board game, the goal is to get"<<endl;
        cout<<"300 points before the computer does"<<endl;
        cout<<"Each time you pass goal you are awarded"<<endl;
        cout<<"100 points, good luck...huh?"<<endl;
        cout<<"**********************************"<<endl;
        cout<<"**********************************"<<endl;
        
        
        char x;
        int r;
        int tile=0;
        int total;
        int g;
        int playerPoints();     
        int pointsTotal();
        int playerOnePosition;
        int move;
        int randomNum=2;//probably dont need this
        int randomize=12;
        int spot;
        int score=0;
	srand (0);
	int maxMove=12;//player cant go over this in one turn
	randomNum=move;

        
        
        //Dice myDice (6);
        //while(myDice.pointsTotal() != 70){//doesnt work need to keep track of points somehow
        while( x != 'n'){ //stopped working all of a sudden, would stop the game, fix later
         //doesnt work need to keep track of where im at on board
        

                
        for(r=1; r<=2000; move=1){
        cout<<"*****Round:"<<r<<"*****"<<endl;
        cout<<playerOne.roll()<<endl;//a 1-6 roll that will keep track of your place on a 20 tile board
        cout<<"You are on tile "<<spot<<", Computer's turn"<<endl;

        
        cout<<"youve earned  "<<playerOne.playerPoints()<<" points"<<endl; //basically a roll i made for myself
        cout<<"Computer earned "<<playerOne.compPoints()<<" points"<<endl; //basically a roll i made for the comp, in his favor
        cout<<"Player 1 score:"<<playerOne.pointsTotal()<<endl; //is bugged just seems to spit out random values
        if(playerOne.pointsTotal()<5){ //probably bugged too
        cout<<"Bonus score hit!"<<endl;}

        cout<<"Would you like to roll again? 'Y' or 'N'"<<endl;
        cin>>x;
        randomNum=(rand ()%maxMove)+move;
        r++;//counts the rounds

        //pointsTotal()+playerPoints();
        cout<<"***********************************"<<endl;
        cout<<"***********************************"<<endl;
        
//      int boardPosition=playerOne.getRolls();
        //cout<<boardPosition<<endl;
        }
        
        
        
        

        }


return 0;
}
//is bugged just seems to spit out random values
You define pointsTotal as 0 + playerPoints and you define playerPoints as a random number. What did you expect?
Only call srand once at the start of your program before generating any random numbers. In your program srand is called 3 times and last time you call it with a fixed seed. That means you will get the same sequence of random numbers each time you run the program.
Topic archived. No new replies allowed.