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!!










share|improve this question

























    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!!










    share|improve this question























      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!!










      share|improve this question













      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 11 at 2:50









      student programmer

      31




      31






















          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).






          share|improve this answer




















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            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

























            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).






            share|improve this answer
























              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).






              share|improve this answer






















                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).






                share|improve this answer












                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).







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 11 at 3:04









                Sam Leatherdale

                11517




                11517



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    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





















































                    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







                    這個網誌中的熱門文章

                    How to read a connectionString WITH PROVIDER in .NET Core?

                    Museum of Modern and Contemporary Art of Trento and Rovereto

                    In R, how to develop a multiplot heatmap.2 figure showing key labels successfully