Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question How Would i get this to run if i were to use only vector statements to

ID: 3761626 • Letter: Q

Question

Question

How Would i get this to run if i were to use only vector statements to keep track of the number of rolls? not as a function but as a vector just to keep track of the number of rolls

#include <iostream>

#include <cstdlib>

#include <ctime>

using namespace std;

int main(){

   int i = 0; // Loop counter iterates numRolls times

   int numRolls = 0; // User defined number of rolls

   int numTwos = 0;

   int numThrees = 0;

   int numFours = 0;

   int numFives = 0;

   int numSixes = 0; // Tracks number of 6s found

   int numSevens = 0;

   int numEights = 0;

   int numNines = 0;

   int numTens = 0;

   int numElevens = 0;

   int numTwelve = 0;//

   int die1 = 0; // Dice values

   int die2 = 0; // Dice values

   int rollTotal = 0; // Sum of dice values

   int idK = 0;

   cout << "Enter number of rolls: " << endl;

   cin >> numRolls;

   srand(time(0));

   while (numRolls >= 0){

       if (numRolls >= 1) {

           // Roll dice numRoll times

           for (i = 0; i < numRolls; ++i) {

               die1 = rand() % 6 + 1;

               die2 = rand() % 6 + 1;

               rollTotal = die1 + die2;

               // Count number of sixs and sevens

               if (rollTotal == 2){

                   numTwos = numTwos + 1;

               }

               else if (rollTotal == 3) {

                   numThrees = numThrees++;

               }

               else if (rollTotal == 4){

                   numFours = numFours++;

               }

               else if (rollTotal == 5){

                   numFives = numFives++;

               }

               else if (rollTotal == 6) {

                   numSixes = numSixes + 1;

               }

               else if (rollTotal == 7) {

                   numSevens = numSevens + 1;

               }

               else if (rollTotal == 8){

                   numEights = numEights++;

               }

               else if (rollTotal == 9){

                   numNines = numNines++;

               }

               else if (rollTotal == 10){

                   numTens = numTens++;

               }

               else if (rollTotal == 11){

                   numElevens = numElevens++;

               }

               else if (rollTotal == 12){

                   numTwelve = numTwelve++;

               }

               cout << endl << "Roll " << (i + 1) << " is "

                   << rollTotal << " (" << die1

                   << "+" << die2 << ")";

           }

           // Print statistics on dice rolls

           cout << endl << endl;

           cout << "Dice roll statistics:" << endl;

           cout << "2s: " << numTwos << endl;

           cout << "3s: " << numThrees << endl;

           cout << "4s: " << numFours << endl;

           cout << "5s: " << numFives << endl;

           cout << "6s: " << numSixes << endl;

           cout << "7s: " << numSevens << endl;

           cout << "8s: " << numEights << endl;

           cout << "9s: " << numNines << endl;

           cout << "10s: " << numTens << endl;

           cout << "11s: " << numElevens << endl;

           cout << "12s: " << numTwelve << endl;

else {

           cout << "Invalid rolls. Try again." << endl;

       }

       return 0;

   }

Explanation / Answer

Here is the code to maintain the similar kind of output, but with vectors, which also reduces the lines of code.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote