Yahtzee Foundation
Mar 23, 2012 at 12:42am UTC
I have to try and make a foundation for a 5ish part Yahtzee project and it has to roll five dice three times and it allows you to keep or reroll a certain die. I'm having trouble though because I have the die to allow the person to keep the die, but it doesn't actually keep the one you chose to keep. I'm not sure exactly how to explain it. You can say that you kept it, but it rerolls it anyway.
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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
#include <iostream>
#include "dice.h"
using namespace std;
const int DiceCount = 5;
const int NumRoll = 3;
const int NumSides = 6;
void RollDice (int myDie[DiceCount], bool Keep [DiceCount]) {
Dice die (NumSides);
int loop;
for (loop = 0; loop < DiceCount; loop++) {
if (Keep [loop])
myDie [loop] = die.Roll ();
cout << myDie [loop];
}
}
void Keepers (bool Keep [DiceCount]) {
char yesNo;
cout << endl << "Would you like to keep the first die? (y/n): " ;
cin >> yesNo;
if (yesNo = 'y' )
Keep [0] = true ;
cout << endl;
cout << "Would you like to keep the second die? (y/n): " ;
cin >> yesNo;
if (yesNo = 'y' )
Keep [1] = true ;
cout << endl;
cout << "Would you like to keep the third die? (y/n): " ;
cin >> yesNo;
if (yesNo = 'y' )
Keep [2] = true ;
cout << endl;
cout << "Would you like to keep the fourth die? (y/n): " ;
cin >> yesNo;
if (yesNo = 'y' )
Keep [3] = true ;
cout << endl;
cout << "Would you like to keep the fifth die? (y/n): " ;
cin >> yesNo;
if (yesNo = 'y' )
Keep [4] = true ;
cout << endl;
}
int main () {
char yesNo;
int myDie [DiceCount];
bool Keep [DiceCount];
int DieCount;
int RollCount;
for (DieCount = 0; DieCount <= DiceCount; DieCount ++){
Keep [DiceCount] = false ;
}
for (RollCount = 0; RollCount < NumRoll; RollCount ++) {
RollDice (myDie, Keep);
cout << endl << "Would you like to reroll? (y/n): " ;
cin >> yesNo;
if (yesNo == 'y' ) {
cout << endl;
Keepers (Keep);
}
}
return 0;
}
Topic archived. No new replies allowed.