GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 28-Nov-2004, 03:47
Nexa Nexa is offline
Awaiting Email Confirmation
 
Join Date: Nov 2004
Location: Florida
Posts: 23
Nexa is on a distinguished road

Possible Use of an Array????


I titled the Thread as, "Possible Use of an Array" becasue, below as you read through my problem, I think that an array will probably be the best way to complete my problem.
Below is what I have of the code so far, basically a program that simulates the game of craps. The "DIFFICULT" part for me is trying to incoporate the following into the program:

- I would like to modify the play to play 1000 games of crap, and keep a track of the statistics in the following fashion:

- How to display the games won on the 1st roll, 2nd roll, ... 20th roll and after the 20th roll?

- How display the games that are lost on the 1st, 2nd, roll, ... 20th roll, and after the 20th roll?

- Displaying the chances of winning at craps?

- How to find my average length of game in the craps program?

- How to display the chances of winning if they improve with the length of the game?

Help anyone??? I am open to any suggestions at this point. :-?
More Help the Better I always say.

CPP / C++ / C Code:
#include <iostream>

using std::cout;
using std::endl;

// contains function prototypes for functions srand and rand
#include <cstdlib>

#include <ctime>   // contains prototype for function time

int rollDice( void );  // function prototype

int main()
{
   // enumeration constants represent game status
   enum Status { CONTINUE, WON, LOST };

   int sum;
   int myPoint;

   Status gameStatus;  // can contain CONTINUE, WON or LOST

   // randomize random number generator using current time
   srand( time( 0 ) ); 

   sum = rollDice();           // first roll of the dice

   // determine game status and point based on sum of dice
   switch ( sum ) {

      // win on first roll
      case 7: 
	   case 11:            
         gameStatus = WON;
         break;

      // lose on first roll
      case 2: 
	   case 3: 
	   case 12:             
         gameStatus = LOST;
         break;

      // remember point
      default:            
         gameStatus = CONTINUE;
         myPoint = sum;
         cout << "Point is " << myPoint << endl;
         break;                // optional   

   } // end switch 

   // while game not complete ...
   while ( gameStatus == CONTINUE ) { 
      sum = rollDice();           // roll dice again

      // determine game status
      if ( sum == myPoint )       // win by making point
         gameStatus = WON;
      else
         if ( sum == 7 )          // lose by rolling 7
            gameStatus = LOST;

   } // end while 

   // display won or lost message
   if ( gameStatus == WON )
      cout << "Player wins" << endl;
   else
      cout << "Player loses" << endl;

   return 0;  // indicates successful termination

} // end main

// roll dice, calculate sum and display results
int rollDice( void )
{
   int die1;
   int die2;
   int workSum;

   die1 = 1 + rand() % 6;  // pick random die1 value
   die2 = 1 + rand() % 6;  // pick random die2 value
   workSum = die1 + die2;  // sum die1 and die2

   // display results of this roll
   cout << "Player rolled " << die1 << " + " << die2
        << " = " << workSum << endl;

   return workSum;         // return sum of dice

} // end main
  #2  
Old 29-Nov-2004, 12:35
aaroncohn's Avatar
aaroncohn aaroncohn is offline
Regular Member
 
Join Date: Feb 2004
Location: Bay Area, CA.
Posts: 564
aaroncohn is a jewel in the roughaaroncohn is a jewel in the roughaaroncohn is a jewel in the rough
Yes, you can use arrays to store all that data. In other news, I thought your forum signature was funny when I first read it. You declare yourself as "THE FUTURE OF PROGRAMING," but you spelled "programming" wrong. Yes, that's right... I can debug your ego.
__________________
-Aaron
  #3  
Old 29-Nov-2004, 12:57
Nexa Nexa is offline
Awaiting Email Confirmation
 
Join Date: Nov 2004
Location: Florida
Posts: 23
Nexa is on a distinguished road
Quote:
Originally Posted by aaroncohn
Yes, you can use arrays to store all that data. In other news, I thought your forum signature was funny when I first read it. You declare yourself as "THE FUTURE OF PROGRAMING," but you spelled "programming" wrong. Yes, that's right... I can debug your ego.


:-) Thanks Man,
  #4  
Old 29-Nov-2004, 13:25
aaroncohn's Avatar
aaroncohn aaroncohn is offline
Regular Member
 
Join Date: Feb 2004
Location: Bay Area, CA.
Posts: 564
aaroncohn is a jewel in the roughaaroncohn is a jewel in the roughaaroncohn is a jewel in the rough
So do you have any questions? You seem to have a lot of stuff to do with that program.
__________________
-Aaron
  #5  
Old 29-Nov-2004, 13:30
Nexa Nexa is offline
Awaiting Email Confirmation
 
Join Date: Nov 2004
Location: Florida
Posts: 23
Nexa is on a distinguished road
Quote:
Originally Posted by aaroncohn
So do you have any questions? You seem to have a lot of stuff to do with that program.

Yes, I do have to preform many things to modify this code, and knowing that arrays is the way, the question is how? I don't even know where to begin how to set up an array in this program to get this statistical data.

Any ideas????

Nexa
  #6  
Old 29-Nov-2004, 20:24
aaroncohn's Avatar
aaroncohn aaroncohn is offline
Regular Member
 
Join Date: Feb 2004
Location: Bay Area, CA.
Posts: 564
aaroncohn is a jewel in the roughaaroncohn is a jewel in the roughaaroncohn is a jewel in the rough
Code:
1. Q: How to display the games won on each roll... A: At the end of a game, if the user won, add 1 to the "wins" count. 2. Q: How to display the games lost on each roll... A: At the end of a game, if the user lost, add 1 to the "losses" column. 3. Q: Displaying the chances of winning at craps.. A: Divide the number of wins by the number of games played. 4. Q: How to find my average length of game in the craps program... A: Get the system time before the game starts, get the system time when the game is over, then subtract the beginning time from the ending time to get the total time of the game. 5. Q: How to display the chances of winning if they improve with the length of the game? A: Store each result in an array and use the array to determine the win/time ratio, assuming one exists. I really doubt it does, but it's your assignment, not mine!
__________________
-Aaron
  #7  
Old 29-Nov-2004, 20:49
Nexa Nexa is offline
Awaiting Email Confirmation
 
Join Date: Nov 2004
Location: Florida
Posts: 23
Nexa is on a distinguished road
Quote:
Originally Posted by aaroncohn
Code:
1. Q: How to display the games won on each roll... A: At the end of a game, if the user won, add 1 to the "wins" count. 2. Q: How to display the games lost on each roll... A: At the end of a game, if the user lost, add 1 to the "losses" column. 3. Q: Displaying the chances of winning at craps.. A: Divide the number of wins by the number of games played. 4. Q: How to find my average length of game in the craps program... A: Get the system time before the game starts, get the system time when the game is over, then subtract the beginning time from the ending time to get the total time of the game. 5. Q: How to display the chances of winning if they improve with the length of the game? A: Store each result in an array and use the array to determine the win/time ratio, assuming one exists. I really doubt it does, but it's your assignment, not mine!


Cool, I'll see what type of code I can conjure up with your supposed algorithim.

Thanks,
Nexa
 
 

Recent GIDBlogStupid Management Policies by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
more array help (simulation project..) dilmv C++ Forum 6 17-Oct-2004 08:51
Speed up C++ code about 3d array! Truong Son C++ Forum 0 16-Mar-2004 22:52
c: array comparison jack C Programming Language 7 26-Jan-2004 12:21
Extra null element in an array samtediou MySQL / PHP Forum 2 11-Dec-2003 12:52

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 04:17.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.