Please help. I really have no idea how to code this.

Program Assignment
Write a program that rolls a set of dice 2500 times and computes:
1- the number of games won and the number of rolls taken before the win, and
2- the number of games lost and the number of rolls taken before the loss.
Use Las Vegas rules for defining wins/losses: http://en.wikipedia.org/wiki/Craps.
The output should look exactly like this (the numbers will change but the
formatting can not);

Games won or lost after the 20th roll
are displayed as the 21st roll.
752 games won and 629 games lost on roll 1
173 games won and 109 games lost on roll 2
253 games won and 297 games lost on roll 3
...
...
11 games won and 52 games lost on roll 20
3 games won and 22 games lost on roll 21
The chances of winning are 1098 / 2500 = 43.9%
The average game length is 3.47 rolls.
Press any key to continue . . .
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
int main()
{
    int dice1,dice2,_roll,_rollCount,_gameCount,_wins,_t_wins,_losts,_t_losts;
	_rollCount=0;
	_gameCount=0;
	do{		
		_roll = (rand() % 2500)+1;
		if ((_roll + _rollCount) > 2500)
			_roll = (2500 - _rollCount);
		
		dice1 = (rand() % 6) + 1;
		dice2 = (rand() % 6) + 1;
		if{}
		else if{}
		else{}
		....		
		
	_rollCount += _roll;		
	}while(_rollCount != 2500);
	
	...
}


Any inspiration?
Also put system("PAUSE"); just before the return in main(). That's where
Press any key to continue . . .
comes from.
closed account (zb0S216C)
Catfish wrote:
Also put system("PAUSE"); just before the return in main().

Sigh. Jftm2000, use this instead of system( ):

1
2
3
4
5
6
7
8
9
10
11
12
void Pause( void )
{
    std::cout << "Press any key to continue..." << std::endl;
    std::cin.ignore( std::numeric_limits < std::streamsize >::max( ), '\n' );
}

int main( )
{
    // ...
    Pause( );
    return 0;
}

Wazzak
im still not sure how you would code the main part of the program?
This is what i have so far. its a bit messy and its not even close to working. I am in desperate need of help. thanks.
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
#include <iostream>

using namespace std;

int main ()
{int numberOfGamesWon, numberOfGamesLost;
    
    
    
    enum result {WIN = 1, LOSE = 2, CONTINUE = 3};
    int rollCount = 0, gameCount = 0;
    
    cout << "Games won or lost after the 20th roll\n"
         << "are displayed as the 21st roll.\n\n";
    
         int rollNumber, dice1, dice2,firstRoll;
    do {
         while ( rollNumber == 0)
         dice1 = (rand () % 6 + 1);
         dice2 = (rand () % 6 + 1);
         firstRoll = dice1 + dice2;
         rollCount++;
                                       
         
         if (firstRoll == 2 || firstRoll == 3 || firstRoll == 12)
                     {
                           result(2);
                           
                     }
                     int roll;
         if (roll == 7 || roll == 11)
               {
                     result(1);
                     
               }
         
         else 
            {  while ( firstRoll != roll || roll != 7)
            {
                        dice1 = (rand () % 6 + 1);
                    dice2 = (rand () % 6 + 1);
                    roll = dice1 + dice2;
                    rollCount++;
                  } }int status;
      if ( roll == firstRoll)
      {
           status=result(1);
      }
      if (roll == 7)
      {status=result(2);
      }      
      
      
      switch ( status)
         {
                case WIN:
                      numberOfGamesWon++;
                     gameCount++;
                    
                     rollNumber = 0;
                case LOSE:
                     numberOfGamesLost++;
                     gameCount++;
                     rollNumber = 0;
         }}
         while (rollCount < 2500);
         cout << "The chances of winning are " << numberOfGamesWon << "/" << numberOfGamesLost << " = " << numberOfGamesWon/numberOfGamesLost << endl;
              return 0;
              system("pause");
              }
           
Topic archived. No new replies allowed.