I have to write the first "part" of the game Yahtzee to include three functions (other than main); RollDice, DisplayBoard, and Keepers. Here are the instructions -
Write a program that will simulate rolling and storing the values of 5 dice. Display the values of the rolls; allow the user to select the values to keep and which to re-roll. Re-roll the needed dice and re-display. Repeat this process again for a maximum of 3 possible rolls.
#include <iostream>
#include "dice.h"
usingnamespace std;
constint DICE_CNT = 5;
constint NUM_ROLL = 3;
constint NUM_SIDES = 6;
void RollDice (int myDie[DICE_CNT], bool Keep [DICE_CNT]) {
// rolls dice and uses Keepers to determine which dice to keep and which to roll again
Dice die (NUM_SIDES);
int count;
for (count = 0; count < DICE_CNT; count ++) {
if (Keep [count])
myDie [count] = die.Roll ();
cout << myDie [count] << "\t";
}
}
void Keepers (bool Keep [DICE_CNT]) {
// asks users which dice they want to keep
char yesNo;
cout << endl << "Would you like to keep die #1? (y/n): ";
cin >> yesNo;
if (yesNo = 'y')
Keep [0] = true;
cout << endl;
cout << "Would you like to keep die #2? (y/n): ";
cin >> yesNo;
if (yesNo = 'y')
Keep [1] = true;
cout << endl;
cout << "Would you like to keep die #3? (y/n): ";
cin >> yesNo;
if (yesNo = 'y')
Keep [2] = true;
cout << endl;
cout << "Would you like to keep die #4? (y/n): ";
cin >> yesNo;
if (yesNo = 'y')
Keep [3] = true;
cout << endl;
cout << "Would you like to keep die #5? (y/n): ";
cin >> yesNo;
if (yesNo = 'y')
Keep [4] = true;
cout << endl;
}
int main () {
// runs DisplayBoard and Keepers
char yesNo;
int myDie [DICE_CNT];
bool Keep [DICE_CNT];
int dcnt;
int rcnt;
for (dcnt = 0; dcnt <= DICE_CNT; dcnt ++){
Keep [DICE_CNT] = false;
}
for (rcnt = 0; rcnt < NUM_ROLL; rcnt ++) {
RollDice (myDie, Keep);
cout << endl << "Would you like to keep any of your dice? (y/n): ";
cin >> yesNo;
if (yesNo == 'y') {
cout << endl;
Keepers (Keep);
}
}
return 0;
}
I don't know what I'm doing wrong but it keeps giving me the error msg "stack around variable Keep was corrupted." What does that mean? And I havent created DisplayBoard yet because I cant figure out how to get it to only display the dice that need to be rolled again?