I don't quite understand what you want to do with the user input. But leaving that aside for now, there is at least one error and some unusual design in the code.
First, the loop
will repeat six times.
m
has the values 0, 1, 2, 3, 4, 5. Unfortunately the array only has room for five values - the last one is an out of bounds access of the array, giving undefined results - the program could crash or behave unpredictably, anything could happen.
Secondly, defining five separate arrays, each with a size of just one, that seems somehow a bit perverse. Wouldn't a single array containing all five values make more sense?
Also, judging from the comments in the code, you want to accumulate the total score from each of the five dice in one of these locations. You might do that like so.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
const int size = 5;
int dices[size] = {0};
int total[size] = {0};
cout << " " << size << " random dice values will appear \n";
for (int m = 0; m < size; m++)
{
dices[m] = rand() % 6 + 1;
cout << "m = " << m << " dices[m] = " << dices[m] << '\n';
total[m] += dices[m];
}
cout << "Totals: ";
for (int m = 0; m < size; m++)
{
cout << setw(4) << total[m];
}
cout << endl ;
return 0;
}
|
Of course, the total is the same as the individual dice score, but if you were to repeat the five throws more than once, it would accumulate all of the scores for each die.
Or - question - did you want to add all five dice together to get the total of the five?