Write a dice rolling game. The game should allow a user to toss up to six dice at a time. Each toss of a die will be stored in a six‐element integer array. The array will be created in the main() function, but passed to a new function called tossDie(). The tossDie() function will take care of generating random numbers from one to six and assigning them to the appropriate array element number. After the dice are tossed, the main() function should display the generated values of the dice.
The above is my problem.
I use an array in the tossDie function but when the array in tossDie function is printed. The elements in that array are more than six and I cannot control and the elements are not random numbers between 1 and 6. This is my approach:
#include <iostream>
#include <time.h>
#include <stdlib.h>
int tossDie(int [], int);
int main() {
srand(time(0));
int a[6]= {'\0'};
int size = 6;
tossDie(a, size);
// printf("The dice results: \n%d", a);
}
int tossDie(int dice[6], int size){
srand(time(0));
int i =0;
for (i =0; i<=6 ; i++){
dice[i] = 1 + rand()%(6);
printf(" %d", dice);
}
return 0;
}