I'm just starting programming and I have to do a dice game, the problem is that when I want to build an accumulator to know how many times each number is repeated, it creshes or reports false numbers
I know it must be something very small in what I'm confusing, but I've been trying for 2 days to get the accumulator right, if anyone can help I'd appreciate it a lot
int unjugador(char nombre[420]) {
int dad[5] , i , j , temp , vectorpospunt[9] , punt=0 , nr=1 , puntp=0
, acum[5] , dec , posj ;
while (punt<10000){
for (i=0; i<6; i++){
acum[i]=0;
}
puntp=0;
posj=99;
cout << "RONDA NRO :" <<nr << endl;
tirardados(dad);
///truchardados(dad);
mostrardados(dad);
for(int i=0;i<5;i++){
for(int j=i+1;j<=5;j++){
if(dad[i]>dad[j]){cout << "acumulador de 1 es : " << acum[0] << endl
;
temp=dad[j];
dad[j]=dad[i];
dad[i]=temp;
}
}
}
///acumulardados(acum, dad);
/**for(i=0;i<6;i++){
acum[i]=contarnumeros(dad, i+1);
}**/
acumulardadosdos(dad , acum );
cout << "acumulador de 1 es : " << acum[0] << endl ;
cout << "acumulador de 2 es : " << acum[1] << endl ;
cout << "acumulador de 3 es : " << acum[2] << endl ;
cout << "acumulador de 4 es : " << acum[3] << endl ;
cout << "acumulador de 5 es : " << acum[4] << endl ;
cout << "acumulador de 6 es : " << acum[5] << endl ;
}
and the functions that probe for the accumulators are:
void acumulardados(int acum[] , int dad[]){
int i , j;
for (i=0;i<6;i++){
for(j=0;j<6;j++){
if(dad[j]==i+1){
acum[i]++;
}
}
}
}
int contarnumeros(int v[], int valorAbuscar){
int i, cantidad=0;
for (i=0;i<6 ;i++ )
{
if (v[i]==valorAbuscar)cantidad++;
}
return cantidad;
}
void acumulardadosdos(int dad[] , int acum[]){
int i ;
for (i=0;i<6;i++){
if (dad[i]==1){
acum[0]++;
}else if (dad[i]==2){
acum[1]++;
}else if (dad[i]==3){
acum[2]++;
}else if (dad[i]==4){
acum[3]++;
}else if (dad[i]==5){
acum[4]++;
}else {
acum[5]++;
}
}
}