printing the wins and losses for each roll
up vote
0
down vote
favorite
I am learning C++ right now and I am kinda confused about how to . I am programming the gambling game CRAPS and I want the output to be like the number of games that are won and lost on the 1st roll, 2nd roll, etc
____ games won and ____ games lost on roll
____ games won and ____ games lost on roll
I am just lost on how to get each count for win and lost after each roll.
I tried including arrays for each time the die are rolled, but it says there's an error of:
invalid types 'int[int]' for array subscript
++wins[roll];
I do not understand what the error means. Can someone help a newbie out? Just need some hints :)
Here is my code so far and what I think I need to change:
unsigned int rollDice();
int wins;
int loses;
int winSum = 0;
int loseSum = 0;
int roll;
int main()
enum class Status CONTINUE, WON, LOST;
srand(static_cast<unsigned int>(time(0)));
unsigned int myPoint0;
Status gameStatus;
unsigned int sumOfDicerollDice();
for (int i = 1; i <=1000; i++)
sumOfDice = rollDice();
roll = 1;
while(Status::CONTINUE == gameStatus)
sumOfDice = rollDice();
++roll;
if (sumOfDice == myPoint)
gameStatus = Status::WON;
else if(sumOfDice == 7)
gameStatus = Status::LOST;
if(roll > 21)
roll = 21;
if (Status::WON == gameStatus)
++wins[roll]; //maybe has smt to do w this one
winSum++;
else
++loses[roll]; //maybe has smt to do w this one
loseSum++;
int totalGame = winSum + loseSum;
int length = 0;
for (int i = 1; i <= 21; i++)
if(i == 21)
cout << wins[i] << " games won and " << loses[i]
<< " games lost on rolls after 20th roll" << endl;
//maybe has smt to do w this one
else
cout << wins[i] << " games won and " << loses[i]
<< " games lost on roll " << i <<endl;
//maybe has smt to do w this one
cout << winSum << "n"<<endl;
cout << loseSum;
unsigned int rollDice()
int die11 + rand()%6;
int die21 + rand()%6;
int sumdie1+die2;
return sum;
Again, tysm for the help!!
c++ arrays
add a comment |
up vote
0
down vote
favorite
I am learning C++ right now and I am kinda confused about how to . I am programming the gambling game CRAPS and I want the output to be like the number of games that are won and lost on the 1st roll, 2nd roll, etc
____ games won and ____ games lost on roll
____ games won and ____ games lost on roll
I am just lost on how to get each count for win and lost after each roll.
I tried including arrays for each time the die are rolled, but it says there's an error of:
invalid types 'int[int]' for array subscript
++wins[roll];
I do not understand what the error means. Can someone help a newbie out? Just need some hints :)
Here is my code so far and what I think I need to change:
unsigned int rollDice();
int wins;
int loses;
int winSum = 0;
int loseSum = 0;
int roll;
int main()
enum class Status CONTINUE, WON, LOST;
srand(static_cast<unsigned int>(time(0)));
unsigned int myPoint0;
Status gameStatus;
unsigned int sumOfDicerollDice();
for (int i = 1; i <=1000; i++)
sumOfDice = rollDice();
roll = 1;
while(Status::CONTINUE == gameStatus)
sumOfDice = rollDice();
++roll;
if (sumOfDice == myPoint)
gameStatus = Status::WON;
else if(sumOfDice == 7)
gameStatus = Status::LOST;
if(roll > 21)
roll = 21;
if (Status::WON == gameStatus)
++wins[roll]; //maybe has smt to do w this one
winSum++;
else
++loses[roll]; //maybe has smt to do w this one
loseSum++;
int totalGame = winSum + loseSum;
int length = 0;
for (int i = 1; i <= 21; i++)
if(i == 21)
cout << wins[i] << " games won and " << loses[i]
<< " games lost on rolls after 20th roll" << endl;
//maybe has smt to do w this one
else
cout << wins[i] << " games won and " << loses[i]
<< " games lost on roll " << i <<endl;
//maybe has smt to do w this one
cout << winSum << "n"<<endl;
cout << loseSum;
unsigned int rollDice()
int die11 + rand()%6;
int die21 + rand()%6;
int sumdie1+die2;
return sum;
Again, tysm for the help!!
c++ arrays
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am learning C++ right now and I am kinda confused about how to . I am programming the gambling game CRAPS and I want the output to be like the number of games that are won and lost on the 1st roll, 2nd roll, etc
____ games won and ____ games lost on roll
____ games won and ____ games lost on roll
I am just lost on how to get each count for win and lost after each roll.
I tried including arrays for each time the die are rolled, but it says there's an error of:
invalid types 'int[int]' for array subscript
++wins[roll];
I do not understand what the error means. Can someone help a newbie out? Just need some hints :)
Here is my code so far and what I think I need to change:
unsigned int rollDice();
int wins;
int loses;
int winSum = 0;
int loseSum = 0;
int roll;
int main()
enum class Status CONTINUE, WON, LOST;
srand(static_cast<unsigned int>(time(0)));
unsigned int myPoint0;
Status gameStatus;
unsigned int sumOfDicerollDice();
for (int i = 1; i <=1000; i++)
sumOfDice = rollDice();
roll = 1;
while(Status::CONTINUE == gameStatus)
sumOfDice = rollDice();
++roll;
if (sumOfDice == myPoint)
gameStatus = Status::WON;
else if(sumOfDice == 7)
gameStatus = Status::LOST;
if(roll > 21)
roll = 21;
if (Status::WON == gameStatus)
++wins[roll]; //maybe has smt to do w this one
winSum++;
else
++loses[roll]; //maybe has smt to do w this one
loseSum++;
int totalGame = winSum + loseSum;
int length = 0;
for (int i = 1; i <= 21; i++)
if(i == 21)
cout << wins[i] << " games won and " << loses[i]
<< " games lost on rolls after 20th roll" << endl;
//maybe has smt to do w this one
else
cout << wins[i] << " games won and " << loses[i]
<< " games lost on roll " << i <<endl;
//maybe has smt to do w this one
cout << winSum << "n"<<endl;
cout << loseSum;
unsigned int rollDice()
int die11 + rand()%6;
int die21 + rand()%6;
int sumdie1+die2;
return sum;
Again, tysm for the help!!
c++ arrays
I am learning C++ right now and I am kinda confused about how to . I am programming the gambling game CRAPS and I want the output to be like the number of games that are won and lost on the 1st roll, 2nd roll, etc
____ games won and ____ games lost on roll
____ games won and ____ games lost on roll
I am just lost on how to get each count for win and lost after each roll.
I tried including arrays for each time the die are rolled, but it says there's an error of:
invalid types 'int[int]' for array subscript
++wins[roll];
I do not understand what the error means. Can someone help a newbie out? Just need some hints :)
Here is my code so far and what I think I need to change:
unsigned int rollDice();
int wins;
int loses;
int winSum = 0;
int loseSum = 0;
int roll;
int main()
enum class Status CONTINUE, WON, LOST;
srand(static_cast<unsigned int>(time(0)));
unsigned int myPoint0;
Status gameStatus;
unsigned int sumOfDicerollDice();
for (int i = 1; i <=1000; i++)
sumOfDice = rollDice();
roll = 1;
while(Status::CONTINUE == gameStatus)
sumOfDice = rollDice();
++roll;
if (sumOfDice == myPoint)
gameStatus = Status::WON;
else if(sumOfDice == 7)
gameStatus = Status::LOST;
if(roll > 21)
roll = 21;
if (Status::WON == gameStatus)
++wins[roll]; //maybe has smt to do w this one
winSum++;
else
++loses[roll]; //maybe has smt to do w this one
loseSum++;
int totalGame = winSum + loseSum;
int length = 0;
for (int i = 1; i <= 21; i++)
if(i == 21)
cout << wins[i] << " games won and " << loses[i]
<< " games lost on rolls after 20th roll" << endl;
//maybe has smt to do w this one
else
cout << wins[i] << " games won and " << loses[i]
<< " games lost on roll " << i <<endl;
//maybe has smt to do w this one
cout << winSum << "n"<<endl;
cout << loseSum;
unsigned int rollDice()
int die11 + rand()%6;
int die21 + rand()%6;
int sumdie1+die2;
return sum;
Again, tysm for the help!!
c++ arrays
c++ arrays
asked Nov 11 at 2:50
student programmer
31
31
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
Make sure to pay close attention to your types.
You have declared the variables wins
and loses
as type int
on lines 2 and 3, however you are trying to use them like an int array where you do ++wins[roll]
and ++loses[roll]
. So you did correctly identify what lines the problem was on, but not what the problem is.
You will have to change the declaration of wins
and loses
to be an array, but also an array that is large enough to hold all the possible values of the dice rolls. Since the dice roll maximum is 12, you should declare wins
and loses
as follows:
int wins[13];
int loses[13];
The reason it is 13 and not 12 is because since arrays start at 0, if you want to be able to store an int at position 12, the array needs to be 13 elements long (0 - 12).
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
Make sure to pay close attention to your types.
You have declared the variables wins
and loses
as type int
on lines 2 and 3, however you are trying to use them like an int array where you do ++wins[roll]
and ++loses[roll]
. So you did correctly identify what lines the problem was on, but not what the problem is.
You will have to change the declaration of wins
and loses
to be an array, but also an array that is large enough to hold all the possible values of the dice rolls. Since the dice roll maximum is 12, you should declare wins
and loses
as follows:
int wins[13];
int loses[13];
The reason it is 13 and not 12 is because since arrays start at 0, if you want to be able to store an int at position 12, the array needs to be 13 elements long (0 - 12).
add a comment |
up vote
0
down vote
accepted
Make sure to pay close attention to your types.
You have declared the variables wins
and loses
as type int
on lines 2 and 3, however you are trying to use them like an int array where you do ++wins[roll]
and ++loses[roll]
. So you did correctly identify what lines the problem was on, but not what the problem is.
You will have to change the declaration of wins
and loses
to be an array, but also an array that is large enough to hold all the possible values of the dice rolls. Since the dice roll maximum is 12, you should declare wins
and loses
as follows:
int wins[13];
int loses[13];
The reason it is 13 and not 12 is because since arrays start at 0, if you want to be able to store an int at position 12, the array needs to be 13 elements long (0 - 12).
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
Make sure to pay close attention to your types.
You have declared the variables wins
and loses
as type int
on lines 2 and 3, however you are trying to use them like an int array where you do ++wins[roll]
and ++loses[roll]
. So you did correctly identify what lines the problem was on, but not what the problem is.
You will have to change the declaration of wins
and loses
to be an array, but also an array that is large enough to hold all the possible values of the dice rolls. Since the dice roll maximum is 12, you should declare wins
and loses
as follows:
int wins[13];
int loses[13];
The reason it is 13 and not 12 is because since arrays start at 0, if you want to be able to store an int at position 12, the array needs to be 13 elements long (0 - 12).
Make sure to pay close attention to your types.
You have declared the variables wins
and loses
as type int
on lines 2 and 3, however you are trying to use them like an int array where you do ++wins[roll]
and ++loses[roll]
. So you did correctly identify what lines the problem was on, but not what the problem is.
You will have to change the declaration of wins
and loses
to be an array, but also an array that is large enough to hold all the possible values of the dice rolls. Since the dice roll maximum is 12, you should declare wins
and loses
as follows:
int wins[13];
int loses[13];
The reason it is 13 and not 12 is because since arrays start at 0, if you want to be able to store an int at position 12, the array needs to be 13 elements long (0 - 12).
answered Nov 11 at 3:04
Sam Leatherdale
11517
11517
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53245427%2fprinting-the-wins-and-losses-for-each-roll%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown