Arrays and Objects

Hey guys,
I recently began developing a cricket simulator game in C++. I created many objects for each player, but now I want to assign a Bowler ID to each object, so that whenever I say "if Over is equal to x, then BowlerID = Bowler[y].

Here is the code so far:
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
#include <iostream.h>
#include <string>

class Team
{
      public:
      std::string Name;
      std::string Location;
      std::string GoverningBody;
      std::string FirstTestMatch;
      std::string FirstODIMatch;
      std::string FirstT20Match;
      std::string PresidentOfGovBody;
      std::string TestCaptain;
      std::string ODICaptain;   
      std::string T20Captain;
};
      
      class TestTeam
      {
      public:
      std::string Name;
      std::string DateOfBirth;
      std::string MajorTeams;
      std::string BattingStyle;
      std::string BowlingStyle;
      unsigned int ODIScore;
      unsigned int TestMatchesPlayed;
      unsigned int TestInnings;
      unsigned int TestRunsScored;
      double TestBattingAvg;
      unsigned int TestHighScore;
      unsigned int TestHundreds;
      unsigned int TestFifties;
      double TestSR;
      unsigned int TestCatches;
      unsigned int TestWicketsTaken;
      double TestBowlingAvg;
      double TestBowlingSR;
      double TestBowlingER;
      };
      
      class ODITeam
      {
      public:
      std::string Name;
      std::string DateOfBirth;
      std::string MajorTeams;
      std::string BattingStyle;
      std::string BowlingStyle;
      unsigned int ODIScore;
      unsigned int ODIMatchesPlayed;
      unsigned int ODIInnings;
      unsigned int ODIRunsScored;
      double ODIBattingAvg;
      unsigned int ODIHighScore;
      unsigned int ODIHundreds;
      unsigned int ODIFifties;
      double ODISR;
      unsigned int ODICatches;
      unsigned int ODIWicketsTaken;
      double ODIBowlingAvg;
      double ODIBowlingSR;
      double ODIBowlingER;
      };

int main()
{
     system("color 17");
     

     Team Team[8];
     Team[1].Name = "India";
     Team[1].Location = "Indian Subcontinent";
     Team[1].GoverningBody = "BCCI";
     Team[1].PresidentOfGovBody = "Shashank Manohar";
     Team[1].FirstTestMatch = "June 25, 1932 vs England";
     Team[1].FirstODIMatch = "July 13, 1974 vs England";
     Team[1].FirstT20Match = "December 1, 2007 vs South Africa";
     Team[1].TestCaptain = "MS Dhoni";
     Team[1].ODICaptain = "MS Dhoni";
     Team[1].T20Captain = "MS Dhoni";
     
     Team[2].Name = "Australia";
     Team[1].Location = "Indian Subcontinent";
     Team[1].GoverningBody = "BCCI";
     Team[1].PresidentOfGovBody = "Shashank Manohar";
     Team[1].FirstTestMatch = "June 25, 1932 vs England";
     Team[1].FirstODIMatch = "July 13, 1974 vs England";
     Team[1].FirstT20Match = "December 1, 2007 vs South Africa";
     Team[1].TestCaptain = "MS Dhoni";
     Team[1].ODICaptain = "MS Dhoni";
     Team[1].T20Captain = "MS Dhoni";

     ODITeam ODIPlayer[8][11];
     // Virender Sehwag - Player 1
     ODIPlayer[1][1].Name = "Virender Sehwag "; 
     ODIPlayer[1][1].DateOfBirth = "October 20, 1978";
     ODIPlayer[1][1].MajorTeams = "India, Asia XI, Delhi Daredevils, Delhi, ICC World XI";
     ODIPlayer[1][1].BattingStyle = "Right-hand Opener";
     ODIPlayer[1][1].BowlingStyle = "Right-arm Offbreak";
     ODIPlayer[1][1].ODIMatchesPlayed = 236;
     ODIPlayer[1][1].ODIInnings = 230;
     ODIPlayer[1][1].ODIRunsScored = 7760;
     ODIPlayer[1][1].ODIBattingAvg = 35.1;
     ODIPlayer[1][1].ODIHighScore = 175;
     ODIPlayer[1][1].ODIHundreds = 14;
     ODIPlayer[1][1].ODIFifties = 37;
     ODIPlayer[1][1].ODISR = 104.1;
     ODIPlayer[1][1].ODICatches = 87;
     ODIPlayer[1][1].ODIWicketsTaken = 92;
     ODIPlayer[1][1].ODIBowlingAvg = 42.4;
     ODIPlayer[1][1].ODIBowlingSR = 45.9;
     ODIPlayer[1][1].ODIBowlingER = 5.3;
     

     // Sachin Tendulkar - Player 2
     ODIPlayer[1][2].Name = "Sachin Tendulkar"; 
     ODIPlayer[1][2].DateOfBirth = "April 24, 1973";
     ODIPlayer[1][2].MajorTeams = "India, Asia XI, Mumbai, Mumbai Indians, Yorkshire";
     ODIPlayer[1][2].BattingStyle = "Riht-hand Bat; Test - Middle Order; ODI - Opening";
     ODIPlayer[1][2].BowlingStyle = "Right-arm Offbreak, Legbreak Googly";
     ODIPlayer[1][2].ODIMatchesPlayed = 453;
     ODIPlayer[1][2].ODIInnings = 442;
     ODIPlayer[1][2].ODIRunsScored = 18111;
     ODIPlayer[1][2].ODIBattingAvg = 45.2;
     ODIPlayer[1][2].ODIHighScore = 200;
     ODIPlayer[1][2].ODIHundreds = 48;
     ODIPlayer[1][2].ODIFifties = 95;
     ODIPlayer[1][2].ODISR = 86.3;
     ODIPlayer[1][2].ODICatches = 136;     
     ODIPlayer[1][2].ODIWicketsTaken = 154;
     ODIPlayer[1][2].ODIBowlingAvg = 44.4;
     ODIPlayer[1][2].ODIBowlingSR = 52.2;
     ODIPlayer[1][2].ODIBowlingER = 5.1;

     
     int x;
     int a, b, c, d, e, f;
     int y;
     int z;
     int k;
     int Score;
     int Wicket;
     int BallResult[6];     
     for(x = 1; x <= 2; x++)
     {
           for(y = 1; y <= 11; y ++)
           {
                 ODIPlayer[x][y].ODIScore = 0;
           }
     }
     
     for(x = 1; x <= 2; y++)
     {
           cout << Team[y].Name << endl;
                      for(y = 1; y <= 11; y++)
                {                

                                 cout << ODIPlayer[x][y].Name << "/t" << ODIPlayer[x][y].ODIScore << endl;
                                 
                }
     cout << "   " << endl;
     }
     srand( time(NULL) );
     for(x = 1; x <=10; x++)
     {
           
     for(z = 1; z <=6; z++)
     {
           BallResult[z] = rand() % 10000 + 1;
     if (BallResult[z] >= 0 && BallResult[z] < 100)
        k = 7;
     else
     if (BallResult[z] >= 100 && BallResult[z] < 900)
        k = 4;
     else
     if (BallResult[z] >= 900 && BallResult[z] < 1200)
        k = 6;
     else
     if (BallResult[z] >= 1200 && BallResult[z] < 5400)
        k = 0;
     else
     if (BallResult[z] >= 5400 && BallResult[z] < 9600)
        k = 1;
     else
     if (BallResult[z] >= 9600 && BallResult[z] < 10000)
        k = 2;
        
     if (k < 7)
          {
               cout << k << " ";
          Score = Score + k;
          }
          else
     if (k = 7)
          {
               cout << "W ";
          Wicket = Wicket + 1;
          }
        }
    cout << endl;
    cout << "-----------------" << endl;
;}
    cout << Score << "/" << Wicket << endl;
     
     cin.ignore();
     return 0;
}
Hey, i was just skimming over your code and saw this (line 196):
if (k = 7)
I think you meant to write this:
if (k == 7)
Sorry though, I am not sure about your question.
Last edited on
I don't know about your question, but I think it would be easier to just do
 
using namespace std;


Instead of doing
1
2
3
std::
std::
std::


Just sayin' :)
but now I want to assign a Bowler ID to each object, so that whenever I say "if Over is equal to x, then BowlerID = Bowler[y].

I don't see any reference in your code to "Over" or a "Bowler" array. Please restate your question. At this point, I'm having trouble understanding what you want...
Well I haven't declared the Over and Bowler array yet .....
If only everyone understood cricket (sigh)
Topic archived. No new replies allowed.