I am writing a dice rolling program that rolls a die and prints a histogram showing the counts of each number's occurrence. (1-6)
For example:
1-xxxxxxx
2-xxx
3-xxxxxxxxx
4-xx
5- 6-x
The program asks the user how many times should the die be rolled so that's how many times the loop should run and roll the die. Each number on the die is represented in the program as a vector element so for example the number of times 5 occurs(say 7 times) would be vector[4] == 7 My problem is that I am not allowed to use a switch statement or if-statements to update the counts of each number. I asked my TA and he told me vector::operator[] would work but I don't even know what that does and the online references don't help. Does anyone have an idea how to accomplish this because I am fairly new to c++ and my prof. hasn't taught much. thanks!
As the information you give in the question is rather little, I assume that you have (almost) everything running and working and you just need to know how to increment the vector by using []
....
int r = random number between 1 and 6
my_vector[r-1] += 1;
thats it :)