<tfoot id='3IoYn'></tfoot>
  • <legend id='3IoYn'><style id='3IoYn'><dir id='3IoYn'><q id='3IoYn'></q></dir></style></legend>

    <i id='3IoYn'><tr id='3IoYn'><dt id='3IoYn'><q id='3IoYn'><span id='3IoYn'><b id='3IoYn'><form id='3IoYn'><ins id='3IoYn'></ins><ul id='3IoYn'></ul><sub id='3IoYn'></sub></form><legend id='3IoYn'></legend><bdo id='3IoYn'><pre id='3IoYn'><center id='3IoYn'></center></pre></bdo></b><th id='3IoYn'></th></span></q></dt></tr></i><div id='3IoYn'><tfoot id='3IoYn'></tfoot><dl id='3IoYn'><fieldset id='3IoYn'></fieldset></dl></div>

    <small id='3IoYn'></small><noframes id='3IoYn'>

      <bdo id='3IoYn'></bdo><ul id='3IoYn'></ul>
      1. 谁能告诉我为什么这些函数没有给我一个合理范围的结果?

        Can anyone tell me why these functions are not giving me a result in a reasonable spectrum?(谁能告诉我为什么这些函数没有给我一个合理范围的结果?)

            • <i id='Nd3wr'><tr id='Nd3wr'><dt id='Nd3wr'><q id='Nd3wr'><span id='Nd3wr'><b id='Nd3wr'><form id='Nd3wr'><ins id='Nd3wr'></ins><ul id='Nd3wr'></ul><sub id='Nd3wr'></sub></form><legend id='Nd3wr'></legend><bdo id='Nd3wr'><pre id='Nd3wr'><center id='Nd3wr'></center></pre></bdo></b><th id='Nd3wr'></th></span></q></dt></tr></i><div id='Nd3wr'><tfoot id='Nd3wr'></tfoot><dl id='Nd3wr'><fieldset id='Nd3wr'></fieldset></dl></div>
              • <bdo id='Nd3wr'></bdo><ul id='Nd3wr'></ul>

                <small id='Nd3wr'></small><noframes id='Nd3wr'>

                  <tbody id='Nd3wr'></tbody>
                <legend id='Nd3wr'><style id='Nd3wr'><dir id='Nd3wr'><q id='Nd3wr'></q></dir></style></legend>

                1. <tfoot id='Nd3wr'></tfoot>
                2. 本文介绍了谁能告诉我为什么这些函数没有给我一个合理范围的结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  下面列出了我正在使用的完整代码,它应该模拟掷骰子游戏并向用户打印详细信息,并允许在用户需要时进行投注.除了实际的掷骰子游戏外,一切正常.它不是仅在没有与 crapsResult 相关联的真值时才循环,而是找到一个真实值和一个由单个负数组成的难以理解的字符串.任何帮助将不胜感激.

                  The full code I am using is listed below, it is supposed to simulate a game of craps and print details to the user and allow for betting if the user desires it. Everything functions except for the actual craps game. Instead of looping only while there is not a truth value associated to crapsResult, it finds one real value and an incomprehensible string of a single negative number. Any help would be appreciated.

                  int main()
                  {
                      //Declare the user input variables
                      int gamesPlayed = 0;
                      char inputPrint = ' ';
                      char isBetting = ' ';
                      int startingBet = 0;
                  
                      //Declare the variables used by the program
                      int endingBet = 0;
                      int currentGame = 0;
                      bool crapsResult;
                      int gamesWon = 0;
                      int gamesLost = 0;
                      double percentWon = 0;
                      bool detailPrint = false;
                  
                      //Prompt the user to input their variables
                      cout << "Enter the number of games to be played: ";
                      cin >> gamesPlayed;
                      while(gamesPlayed < 1)
                      {
                          cout << "   Error: must be greater than 0" << endl;
                          cout << "Enter the number of games to be played: ";
                          cin >> gamesPlayed;
                          cin.clear();
                          cin.ignore();
                      }
                  
                      cout << "Do you wish to print details (Y/N): ";
                      cin >> inputPrint;
                      if(inputPrint == 'y' || inputPrint == 'Y')
                      {
                          detailPrint = true;
                      }
                  
                      cout << "Do you wish to bet (Y/N): ";
                      cin >> isBetting;
                  
                      if(isBetting == 'y' || isBetting == 'Y')
                      {
                          cout << "Enter money to start betting with: ";
                          cin >> startingBet;
                          while(startingBet < 1)
                          {
                              cout << "   Error: must be greater than 0" << endl;
                              cout << "Enter the number of games to be played: ";
                              cin >> gamesPlayed;
                              cin.clear();
                              cin.ignore();
                          }
                      }
                      //Seed the random number generator
                      srand(time(NULL));
                  
                      //Set a value for ending bet
                      if(startingBet == 0)
                      {
                          endingBet = 1;
                      }
                      else
                      {
                          endingBet = startingBet;
                      }
                      //Call playcraps to simulate the game for as many games as the user input
                      for(currentGame = 1; currentGame <= gamesPlayed && endingBet > 0; currentGame += 1)
                      {
                          crapsResult = NULL;
                          crapsResult = playCraps(currentGame, detailPrint, isBetting, startingBet);
                          if(crapsResult == true)
                          {
                              gamesWon += 1;
                              endingBet = betting(endingBet, crapsResult);
                          }
                          if(crapsResult == false)
                          {
                              gamesLost += 1;
                              endingBet = betting(endingBet, crapsResult);
                          }
                          if((isBetting == 'Y' || isBetting == 'y') && (detailPrint == true))
                          {
                              cout << "Money left is $" << endingBet << endl;
                          }
                      }
                  
                      //Calculate the percentage of games won
                      percentWon = (double(gamesWon) / double(currentGame-1)) * 100.0;
                  
                      //Print the results to the user
                      if(isBetting == 'Y' || isBetting == 'y')
                      {
                          cout << "Money at end of games is $" << endingBet << endl;
                      }
                      cout << "The number of games played is " << currentGame - 1 << endl;
                      cout << "The number of games won is " << gamesWon << endl;
                      cout << "The number of games lost is " << gamesLost << endl;
                      cout << "The percent of games won is " << fixed << showpoint << setprecision(3) << percentWon << endl;
                  }
                  
                  //Simulates the roll of a single die and returns the result
                  int roll()
                  {
                      int rollResult = 0;
                      rollResult = rand() % 6 + 1;
                      return rollResult;
                  }
                  
                  //Calls roll twice and returns the sum of the two results
                  int roll2Dice()
                  {
                      //Declare variables for this function
                      int rollOne = 0;
                      int rollTwo = 0;
                      int rollSum = 0;
                  
                      //Find rollOne and rollTwo
                      rollOne = roll();
                      rollTwo = roll();
                  
                      //Find rollSum
                      rollSum = rollOne + rollTwo;
                  
                      return rollSum;
                  }
                  
                  bool playCraps(int currentGame, bool detailPrint, char isBetting, int startingBet)
                  {
                      bool crapsResult = NULL;
                      int currentGameStorage[100];
                      int currentRoll = 1;
                      int point = roll2Dice();
                      int printingNumber = 0;
                      currentGameStorage[0] = point;
                      if(point == 7 || point == 11)
                      {
                          crapsResult = true;
                      }
                      else if(point == 2 || point == 3 || point == 12)
                      {
                          crapsResult = false;
                      }
                      else
                      {
                          crapsResult = NULL;
                      }
                      while(crapsResult != true && crapsResult != false)
                      {
                          currentGameStorage[currentRoll] = roll2Dice();
                          if(currentGameStorage[currentRoll] == point)
                          {
                              crapsResult = true;
                          }
                          else if(currentGameStorage[currentRoll] == 7)
                          {
                              crapsResult = false;
                          }
                          currentRoll += 1;
                      }
                      if(detailPrint == true)
                      {
                          cout << "Game " << currentGame << ": ";
                          for(printingNumber = 0; printingNumber <= currentRoll; printingNumber += 1)
                          {
                              cout << currentGameStorage[printingNumber] << " ";
                          }
                          if(crapsResult == true)
                          {
                              cout << "win";
                          }
                          else if(crapsResult == false)
                          {
                              cout << "lose";
                          }
                          cout << endl;
                      }
                      return crapsResult;
                  }
                  
                  int betting(int endingBet, bool crapsResult)
                  {
                      if(crapsResult == true)
                      {
                          endingBet += 1;
                      }
                      else if(crapsResult == false)
                      {
                          endingBet -= 1;
                      }
                      return endingBet;
                  }
                  

                  推荐答案

                  只是略读了一下,并没有阅读你的所有代码(所以也可能有其他问题),但这行肯定有问题:

                  Just skimmed and didn't read all of your code (so there may be other things wrong too), but this line is definitely problematic:

                  while(crapsResult != true && crapsResult != false)
                  

                  crapsResult 同时为both假在逻辑上是不可能的,因此永远不会进入循环.

                  It is logically impossible for crapsResult to simultaneously be both true and false, so that loop will never be entered.

                  这篇关于谁能告诉我为什么这些函数没有给我一个合理范围的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  What is inside .lib file of Static library, Statically linked dynamic library and dynamically linked dynamic library?(静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么?)
                  How do I load a C DLL from the SXS in Python?(如何从 Python 中的 SXS 加载 C DLL?)
                  Can Cython code be compiled to a dll so C++ application can call it?(Cython 代码可以编译成 dll 以便 C++ 应用程序可以调用它吗?)
                  Delay Loading DLLs(延迟加载 DLL)
                  Throwing C++ exceptions across DLL boundaries(跨 DLL 边界抛出 C++ 异常)
                  Loading a dll from a dll?(从 dll 加载 dll?)

                  <small id='l8Yj1'></small><noframes id='l8Yj1'>

                    <tfoot id='l8Yj1'></tfoot>
                    • <i id='l8Yj1'><tr id='l8Yj1'><dt id='l8Yj1'><q id='l8Yj1'><span id='l8Yj1'><b id='l8Yj1'><form id='l8Yj1'><ins id='l8Yj1'></ins><ul id='l8Yj1'></ul><sub id='l8Yj1'></sub></form><legend id='l8Yj1'></legend><bdo id='l8Yj1'><pre id='l8Yj1'><center id='l8Yj1'></center></pre></bdo></b><th id='l8Yj1'></th></span></q></dt></tr></i><div id='l8Yj1'><tfoot id='l8Yj1'></tfoot><dl id='l8Yj1'><fieldset id='l8Yj1'></fieldset></dl></div>

                      <legend id='l8Yj1'><style id='l8Yj1'><dir id='l8Yj1'><q id='l8Yj1'></q></dir></style></legend>

                          • <bdo id='l8Yj1'></bdo><ul id='l8Yj1'></ul>
                              <tbody id='l8Yj1'></tbody>