I cant figure out why this D::D:: is coming up when i generate a random number. idk i looked at other pages and the code looks fine .

int roll_hold( char answer1, char answer2)
{
    int numb_on_dice1,numb_on_dice2,play1, play2,next_player,play1_total, play2_total;
    char f,s;// first and second player.
    cout<< " Would you like to roll or hold? press r for roll and h for hold:" << endl;// ask user if want to roll or hold
    do
    {
            cout << " Player 1 turn:: ";
            cin >> answer1; //gets answer
            cout << " Player 2 turn:: ";
            cin >> answer2;

            if(answer1=='r') // if  chooses to roll
              {

                  numb_on_dice1 = ( (rand() % 7)); // computes roll.

                                    cout <<  (((next_player % 1) ==2) ? f:s) << ":: " ;// alternates players.
                numb_on_dice1++;// keeps value
                play1_total= numb_on_dice1++; // play1_total gets value of saved values
                       if (play1_total==100)
                            {
                                cout << " Player 1 you win " << endl;
                            }
              }
              else{
                       cout << " you wish to hold " << endl;
                       cout << " Player 1 score is :: " << play1_total << endl;// displays total score
                       cout << " Player 2 score is :: " << play2_total << endl;
                            if ( play1_total > play2_total)
                                {
                                    cout << " Player 1 you win " << endl;
                                }
                   }
                if (answer2=='r')
                  {
                        numb_on_dice2 = ((1+rand() % 7)); // computes roll.


                        cout << (((next_player % 2) ==1) ? f:s) << ":: " ;

                        numb_on_dice2++;
                        play2_total= numb_on_dice2++;
                          if (play2_total==100)
                                {
                                   cout << " Player 2 you win " << endl;
                                }
                    cin >> answer1;
                    numb_on_dice1++;
                   }
            else{
                       cout << " you wish to hold " << endl;
                       cout << " Player 1 score is :: " << play1_total << endl;
                       cout << " Player 2 score is :: " << play2_total << endl;

                            if ( play1_total < play2_total)
                                {
                                    cout << " Player 2 you win " << endl;
                                }
                }
    }while (( play1_total) &&( play2_total <=50));
    {
             cout << " Player 1 score is :: " << play1_total << endl;;
                       cout << " Player 2 score is :: " << play2_total << endl;

                            if ( play1_total < play2_total) // show who wins player 1 or player 2
                                {
                                    cout << " Player 2 you win " << endl;
                                    {
                                         if ( play1_total > play2_total)
                                            {
                                            cout << " Player 1 you win " << endl;
                                            }
                                    }
                                }
    }
    return play1_total, play2_total;

Edited 6 Years Ago by timbomo: n/a

I suggest making the smallest compilable code that demonstrates your problem (< 15 lines). It will help you narrow down where the problem is, and if you still can't figure it out, it will save us massive time helping you debug it.

Dave

I thought if i were to use the ( ++ ) in play1_toal it would store the values and add them up. but its not, can someone tell me what i should do instead.

I cant figure out why this D::D:: is coming up when i generate a random number. idk i looked at other pages and the code looks fine .

int roll_hold( char answer1, char answer2)
{
    int numb_on_dice1,numb_on_dice2,play1, play2,next_player,play1_total, play2_total;
    char f,s;// first and second player.
    cout<< " Would you like to roll or hold? press r for roll and h for hold:" << endl;// ask user if want to roll or hold
    do
    {
            cout << " Player 1 turn:: ";
            cin >> answer1; //gets answer
            cout << " Player 2 turn:: ";
            cin >> answer2;
            if(answer1=='r') // if  chooses to roll
              {

                  numb_on_dice1 = ( (rand() % 7)); // computes roll.

                                    cout <<  (((next_player % 1) ==2) ? f:s) << ":: " ;// alternates players.
                numb_on_dice1++;// keeps value
                play1_total= numb_on_dice1++; // play1_total gets value of saved values
                       if (play1_total==100)
                            {
                                cout << " Player 1 you win " << endl;
                            }
              }
              else{
                       cout << " you wish to hold " << endl;
                       cout << " Player 1 score is :: " << play1_total << endl;// displays total score
                       cout << " Player 2 score is :: " << play2_total << endl;
                            if ( play1_total > play2_total)
                                {
                                    cout << " Player 1 you win " << endl;
                                }
                   }
                if (answer2=='r')
                  {
                        numb_on_dice2 = ((1+rand() % 7)); // computes roll.


                        cout << (((next_player % 2) ==1) ? f:s) << ":: " ;

                        numb_on_dice2++;
                        play2_total= numb_on_dice2++;
                          if (play2_total==100)
                                {
                                   cout << " Player 2 you win " << endl;
                                }
                    cin >> answer1;
                    numb_on_dice1++;
                   }
            else{
                       cout << " you wish to hold " << endl;
                       cout << " Player 1 score is :: " << play1_total << endl;
                       cout << " Player 2 score is :: " << play2_total << endl;

                            if ( play1_total < play2_total)
                                {
                                    cout << " Player 2 you win " << endl;
                                }
                }
    }while (( play1_total) &&( play2_total <=50));
    {
             cout << " Player 1 score is :: " << play1_total << endl;;
                       cout << " Player 2 score is :: " << play2_total << endl;

                            if ( play1_total < play2_total) // show who wins player 1 or player 2
                                {
                                    cout << " Player 2 you win " << endl;
                                    {
                                         if ( play1_total > play2_total)
                                            {
                                            cout << " Player 1 you win " << endl;
                                            }
                                    }
                                }
    }
    return play1_total, play2_total;

end quote.

I thought if i were to use the ( ++ ) in play1_toal it would store the values and add them up. but its not, can someone tell me what i should do instead.

Edited 3 Years Ago by mike_2000_17: Fixed formatting

This article has been dead for over six months. Start a new discussion instead.