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

#####hello, just having trouble with what values to pass any help would be appre

ID: 3689552 • Letter: #

Question

#####hello, just having trouble with what values to pass any help would be appreciated. thanks in advance.#####

####program directions#####

This program will store 500 dice throws (ie random numbers between 1 and 6) in an array via the function called generateData.
Then in a for-loop it will call the function called countValue 6 times where countValue will scan the 500 array positions. The first call it will tally how many "1" throws there were, the second call, how many 2 throws..etc until reaching 6

1 - The function generateData will receive the data array as alias "d" and a 500 limit as alias "cnt".

     It will compute a random number between 1 and 6 and store it in the dice variable.
     Then it will move that value into d[i]...i is 1, then 2, then 3..etc .
     So each loop iteration causes the next dice throw to be stored in the next available position of array d.

2 - The function countValue will receive the data array, the 500 limit and the current value of the for-loop "i" variable as alias values d, howmany and value, respectively.

3 - Inside function countValue...use an if statement to see if the ith position of array d is equal to its alias "value"

     ...adding one to total if that is so

####program below

// Complete the following program
// The program generates 500 numbers between 1 and 6 and stores them in an array
// The program loops and counts how many times each number occurs

#include <iostream>
#include <cmath>
#include <ctime>
#include <cstdlib>
using namespace::std;

void generateData(int[], int count);

int countValue(const int[], int howMany, int value);

void main()
{
   int data[1000];
  
   generateData(data, 500); //not sure what to pass as refernece?call the function to generate 500 numbers between 1 and 6
                       // storing the values in the data array

   for (int i = 1; i <= 6; i++)
   {
       cout << i << " " << countValue() << endl; //not sure what to pass as refernece?call the countValue function
   }
}

void generateData(int d[], int cnt)
{
   srand(12345);
   int dice;
   for (int i = 0; i < cnt; i++)
   {
       dice = (rand() % 6) + 1; // generate a random number between 1 and 6
       d[i] = dice; // store it in the next position
   }
}

int countValue(const int d[], int howMany, int value)
{
   int total = 0;
   for (int i = 0; i < howMany; i++)
   {
       if ( i == value) // adjust the total if number in cell i is equal to the parameter "value"
       {
           total += 1;
       }
   }
   return total;
}

Explanation / Answer

#include <iostream>
#include <cmath>
#include <ctime>
#include <cstdlib>
using namespace::std;
void generateData(int[], int count);
int countValue(int[], int howMany, int value);
int main()
{
int data[1000];
  
generateData(data, 500); //not sure what to pass as refernece?call the function to generate 500 numbers between 1 and 6
// storing the values in the data array
for (int i = 1; i <= 6; i++)
{
cout << i << " " << countValue(data,500,i) << endl; //not sure what to pass as refernece?call the countValue function
}
return 0;
}
void generateData(int d[], int cnt)
{
srand(12345);
int dice;
for (int i = 0; i < cnt; i++)
{
dice = (rand() % 6) + 1; // generate a random number between 1 and 6
d[i] = dice; // store it in the next position
}
}
int countValue(int d[], int howMany, int value)
{
int total = 0;
for (int i = 0; i < howMany; i++)
{
if ( d[i] == value) // adjust the total if number in cell i is equal to the parameter "value"
{
total += 1;
}
}
return total;
}