I'm really not understanding arrays; for my project I had to simulate a die rolling 2,000 times and keep track of how many times each was rolled. How can I fix this? :
for(i=0, i<=rolls, i++){
die = (rand()%6)+1;
rolls[die] = rolls[die]+1;
}
First of all, this for loop is going to execute 2001 times. Also, the value of die will be between 1 and 6 inclusive, but your array indices will be between 0 and 5 inclusive. So when die == 6 and the statement rolls[die] = rolls[die] + 1 executes, the array index will be out of bounds
The second for loop will also cause an array index out of bounds error
Remember if an array size is n, the array indices will range from 0 to n-1. Counting usually starts from 0, not 1.