I was given the code below by my proffesor, and asked to modify it so it can keep track of how many times it receives a particular result and prints an asterisk accordingly. I put in the results hes looking for at the bottom. I"m not asking for anyone to solve it for me but maybe give me something to think about or guide me in the right direction. Thank you for your time and effort.
int n, i;
int r;
srand(time(NULL)); // Set seed for random numbers.
cout << "Enter number of dice to roll: ";
cin >> n;
for (i = 1; i <= n; i++) {
r = rand() % 6 + 1; // Get a number 1 to 6
cout << r << " ";
}
return 0;
}
Enter number of dice to roll: 20
22632341434554333342
Value Freq Graph
1 1*
2 4 ****
3 7 *******
4 5 *****
5 2 *
6 1 *
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <ctime>
usingnamespace std;
int main()
{
int n, i;
int r;
srand(time(NULL)); // Set seed for random numbers.
cout << "Enter number of dice to roll: ";
cin >> n;
for (i = 1; i <= n; i++)
{
r = rand() % 6 + 1; // Get a number 1 to 6
cout << r << " ";
// keep track of how many times it receives a particular result
// how would you keep track of 6 different elements?
}
//prints an asterisk accordingly
// once you have a set of counts, one count for each die value, simply
// print an asterisk for each count
}
You could create an array of size 6, and initialize it to zeros. With each roll, increase the array location by one. Of course, you need to subtract one from the roll before the increase, since arrays start with 0. When all the rolls are finished, print out in amount of stars, the number in each array location.