Thoughts from Homework 6

These examples were taken from submitted solutions to Homework 6.

Presently they are included anonymously. If you would like credit for your code (or would like to have it removed), send me email.

Initialize, unless you are really sure

```    int three, two;
for (j=1; j<7; j++){
if (count[j]== 3){
three++;
}
if (count[j]== 2){
two++;
}

}
```

Out of bounds

Arrays end one less than the size

```    int i;

int dice2[6];

for(i = 0; i <= 6; i++){
dice2[i]= 0;
}
```

Arrays start at zero

```    for(i = 0; i <5; i++){
dice2[dice[i]]=dice2[dice[i]]+1;
if (dice2[dice[i]]>=3){
return scoreChance(dice);
}
}
```

Don't ignore warnings

```int scoreChance(int dice[])
{
int sum;
sum = sumElements;

return(sum);
}
```

For what?

Whatever for

```    for(int i=0; i<=6; i++){
if      (histo[0] == 5) {return 50;}
else if (histo[1] == 5) {return 50;}
else if (histo[2] == 5) {return 50;}
else if (histo[3] == 5) {return 50;}
else if (histo[4] == 5) {return 50;}
else if (histo[5] == 5) {return 50;}
}
```

Missing an inner for

```    for (i = 0; i < 6; i++) {
if (dice[i] == 1) histo[0]++;
if (dice[i] == 2) histo[1]++;
if (dice[i] == 3) histo[2]++;
if (dice[i] == 4) histo[3]++;
if (dice[i] == 5) histo[4]++;
if (dice[i] == 6) histo[5]++;
}
```

A for too far

```int count[6] = {0,0,0,0,0,0};
for (b=0; b<5; ++b){
for (d=1; d<6; ++d){
if (dice[b]==d)
++count[d];
}
}
```

That's what arrays are for

```    for(a=0; a<5; a++){
if(dice[a]==1){
num_of_ones++;
}
else if(dice[a]==2){
num_of_twos++;
}
else if(dice[a]==3){
num_of_threes++;
}
else if(dice[a]==4){
num_of_fours++;
}
else if(dice[a]==5){
num_of_fives++;
}
else if(dice[a]==6){
num_of_sixes++;
}
}
int num_of[]={num_of_ones,num_of_twos,num_of_threes,num_of_fours,num_of_fives,num_of_sixes};
```

In need of braces and indentation

```  for (int i=0; i<6; ++i){
if (histo[0]==0||histo[1]==0||histo[4]==0||histo[5]==0)
if (histo[i]==1)
newTotal= newTotal+1;
if (histo[i]==2)
newTotal= newTotal+2;
if (newTotal==5)
return 30;
}
```