Int winssize initializing the win array int

  • No School
  • AA 1
  • 12

This preview shows page 4 - 9 out of 12 pages.

int wins[SIZE]={}; //Initializing the win array int losses[SIZE]={}; //Initializing the loss array //Initialize variables string inName="GameInfo.dat"; //String Name char outName[]="GameStats.dat"; //Character Array Name; //Open the Input file; //Open the Output file
Image of page 4
while(in>>nGames);//Last value in file becomes the number of games nGames=nGames>lmGames?lmGames:nGames;//Limit games if to high //Play the game the prescribed number of times. int beg=time(0);//Time the game play crpGame(wins,losses,SIZE,nGames,numThrw,mxThrw); int end=time(0);//End time of Game play //Output the game statistics to the screen out<<"Total time to play these Games in integer seconds = "< scrnDsp(wins,losses,SIZE,nGames,numThrw,mxThrw); //Output the game statistics to the screen cout<<"Total time to play these Games in integer seconds = "<
Image of page 5
fileDsp(out,wins,losses,SIZE,nGames,numThrw,mxThrw); //Close files in.close(); out.close(); //Exit stage right return 0; } void crpGame(int wins[],int losses[],int SIZE,int &nGames, int &numThrw,int &mxThrw){ for(int game=1;game<=nGames;game++){ //Throw dice and sum, keep track of number of throws in a game int gmThrw=1; char sum1=rollDie(6);
Image of page 6
//Determine wins and losses switch(sum1){ case 7: case 11:wins[sum1]++;break; case 2: case 3: case 12:losses[sum1]++;break; default:{ //Loop until a 7 or previous sum is thrown bool thrwAgn=true; do{ //Throw the dice again char sum2=rollDie(6); gmThrw++;//Increment the number of throws
Image of page 7
if(sum2==7){ losses[sum1]++; thrwAgn=false; }else if(sum1==sum2){ wins[sum1]++; thrwAgn=false; }//end of dependent if-else
Image of page 8
Image of page 9

You've reached the end of your free preview.

Want to read all 12 pages?

  • Fall '19
  • Dice, char rollDie

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes
A+ icon
Ask Expert Tutors