Hi I have made some progress on the code. Thanx for the help. Here is what I have so far. This is what we have to add to the code now if anyone could help out.
- Allow the player to select which values to keep and which to regenerate each time.
- Ensure that user selects a valid row each time (a row not previously used).
- Only display a value in a row if it is used (i.e.: display nothing if the row is unused)
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int dice[5], Row, score[5]={0,0,0,0,0,}, reroll=1, total,bonus=63;
int fRoll();
void fTotal();
void fScore();
int main() {
int i, s;
srand(time(NULL));
do {
for (s = 0; s < 6; s++) {
for (int i = 0; i < 5; i++) {
dice[i] = fRoll();
printf ("\t%d: %d\n",i+1, dice[i]);
}
if (reroll<3){
do {
printf ("\n\tRow to use? 0 to Reroll ");
scanf ("%i",&Row);
} while (Row<0 || Row>6);
if (Row == 0 ) {
printf ("\n\t---Reroll---\n");
reroll ++;
s--;
dice[i] = fRoll();
}else if (Row == 1){
fScore();
}else if (Row == 2){
fScore();
}else if (Row == 3){
fScore();
}else if (Row == 4){
fScore();
}else if (Row == 5){
fScore();
}else if (Row == 6){
fScore();
} else if (Row > 6 || Row < 1){
printf ("Please enter a number between 1 and 6!\n");
s--;
}
}else if (reroll==3){
do {
printf ("\n\tRow to use? Can't Reroll! ");
scanf ("%i",&Row);
} while (Row<1 || Row>6);
if (Row == 1){
fScore();
}else if (Row == 2){
fScore();
}else if (Row == 3){
fScore();
}else if (Row == 4){
fScore();
}else if (Row == 5){
fScore();
}else if (Row == 6){
fScore();
} else if (Row > 6 || Row < 1){
printf ("Please enter a number between 1 and 6!\n");
s--;
}
}
}
}while (s < 6);
fTotal();
}
int fRoll() {
int dice[5];
for (int i = 0; i < 5; i++) {
dice[i] = (rand()%6)+1;
return dice[i];
}
}
void fTotal(){
total=0;
for (int i = 1; i < 7; i++) {
total = total + score[i];
}
if (total >= 63){
total = total + 35;
}
printf ("\n\tTotal is %i", total);
}
void fScore(){
score[Row] = 0;
for (int i = 0; i < 5; i++){
if (dice[i] == Row){
score[Row] += Row;
}
}
reroll =1;
bonus = bonus - score[Row];
printf ("\tScore = %i\n\n", score[Row]);
printf ("\tYou now need %i to get the bonus\n\n",bonus);
}