the int myArray [12] at line 101 in my code keeps 12 elements |
Yes, I understand that. It keeps track of how many times each number has been rolled. Your code fails to initialize the array. See my lines 4-5.
As I pointed out previously, your line 107 is defective.
|
cin >> diceThrows[myArray];
|
diceThrows is not an array and myArray is a pointer. That line will NOT work.
As I understood option #4, the object was to roll the dice until the user's point (value) was made (like craps) and then display a histogram of how many times each number was rolled. Your code does not do that.
but the dice roll can have its value till 400 |
Where does the 400 come from? That's not in the original problem statement. The value of a diceRoll is 2-12. Your code rolls the dice once at line 108. You then execute the following line 12 times varying k:
cout <<"The value " << k << " was rolled " << dice << " times ";
Note that the value of dice does not change and it it NOT the number of rolls of a particular number. Lets assume the value of dice from line 108 was 7:
The value 1 was rolled 7 times // This isn't even possible
The value 2 was rolled 7 times
...
The value 12 was rolled 7 times
This is why it's necessary to increment the array indexed by what was rolled (my line 10).
The following line is also defective:
|
percentage = ((double)dice/(double)diceThrows) * 100;
|
Assuming again that 7 was rolled, this will divide 7 by 0 (diceThrows was never incremented).
Your display of the histogram is also defective. Again assuming 7 was rolled at line 108, your histogram will display 7 "o"s for every value from 1-12.