正在创建Yahtzee游戏,但在重新滚动时遇到问题(C++)

正在创建Yahtzee游戏,但在重新滚动时遇到问题(C++),c++,C++,我现在很难让我的滚筒100%正常工作。有时它的行为是正确的,只是改变了我的选择,但有时它似乎有自己的想法。下面是我代码中的一些片段 Int main() ... while (counter<13){ cout<< playName << " please roll the dice."<<endl; system("pause"); roll(); reRoll();

我现在很难让我的滚筒100%正常工作。有时它的行为是正确的,只是改变了我的选择,但有时它似乎有自己的想法。下面是我代码中的一些片段

  Int main()
  ...
  while (counter<13){
        cout<< playName << " please roll the dice."<<endl;
        system("pause");
        roll();
        reRoll();
        reRoll();
        score();}



  void reRoll(){
cout<< playName << " please select which dice you would like to re-roll by entering
   a y or n."<<endl;
cout<< "Would you like to re-roll die 1?";
cin>>dieOne;
cout<< "Would you like to re-roll die 2?";
cin>>dieTwo;
cout<< "Would you like to re-roll die 3?";
cin>>dieThree;
cout<< "Would you like to re-roll die 4?";
cin>>dieFour;
cout<< "Would you like to re-roll die 5?";
cin>>dieFive;

srand(static_cast<unsigned int>(time(0)));
const int dice = 6;
int die[6] = {1, 2, 3, 4, 5, 6};

if (dieOne=="y"){
    int dice1Roll = (rand() % dice);
    currentDice[0] = die[dice1Roll];}
if (dieOne!="y"){}
if (dieTwo=="y"){
    int dice2Roll = (rand() % dice);
    currentDice[1] = die[dice2Roll];}
if (dieTwo!="y"){}
if (dieThree=="y"){
    int dice3Roll = (rand() % dice);
    currentDice[2] = die[dice3Roll];}
if (dieThree!="y"){}
if (dieFour=="y"){
    int dice4Roll = (rand() % dice);
    currentDice[3] = die[dice4Roll];}
if (dieFour!="y"){}
if (dieFive=="y"){
    int dice5Roll = (rand() % dice);
    currentDice[4] = die[dice5Roll];}
if (dieFive!="y"){}
cout<<playName<<"'s die are now "<<currentDice[0]<<" "<<currentDice[1]<<" "
    <<currentDice[2]<<" "<<currentDice[3]<<" "<<currentDice[4]<<endl;}

在使用rand函数之前,不必每次都调用srand。无论你在做什么,只要简单地说一次就足够了:

#include <cstdlib>

int main(void) {
    srand(static_cast<unsigned int>(time(NULL)));

    while(...) {}
    return 0
}

你为什么要用ifdieOne=y{}线?当它有自己的想法时它会做什么?欢迎来到SO!为了让我们及时帮助您,请提供一个运行示例,包括所有的输入和输出。是的,我本来打算添加一张图片,但我还没有10个代表。不管怎样,当它有自己的想法时,它要么改变所有5个骰子,不管输入是什么,要么随机选择要改变的5个骰子中的哪一个。最后一次重新滚动是错误发生的地方。大家好,欢迎来到Yahtzee。请输入玩家数量:2名玩家1名,请输入您的姓名:mat mat请掷骰子。按任意键继续。滚动垫滚动4 4 2 6 3垫请输入y或n选择要重新滚动的骰子。你想重铸模具1?n你想重铸模具2?n你想重铸模具3?n你想重铸模具4?y你想重铸模具5?很好,但它没有回答我的问题。是的,但你没有真正问问题。我只是做了一些观察并向你们指出。例如,您如何声明die[1、2、3、4、5]它们是string、char还是char*?根据变量类型的不同,这可能会导致您遇到的问题
int dice1Roll = (rand() % dice) + 1;