因此,对于这个作业,我需要为游戏Mastermind打印3种不同测试方法的结果。我需要基本上打印出平均每个方法尝试猜测正确答案的次数。出于某种原因,它不会打印出结果。我觉得它在无限循环中。
bool play = true; // bool to create cycles
bool enableOutput;
int repeat = 0;
int countOne = 0;
int countTwo = 0;
int countThree = 0;
int sumOne = 0;
int sumTwo = 0;
int sumThree = 0;
bool randAnswer;
while ( play == true ) // while bool is true
{
enableOutput = true;
randAnswer = false;
answer = generateAnswer( randAnswer ); // creating answer
methodicalEliminate ( answer, enableOutput ); // 1st method to test
guessAndEliminate ( answer, enableOutput ); // 2nd method to test
guessThreeThenEliminate ( answer, enableOutput ); // 3rd method to test
enableOutput = false;
for ( repeat = 0; repeat <= 100; repeat++ )
{
randAnswer = true;
answer = generateAnswer( randAnswer ); // creating answer
methodicalEliminate ( answer, enableOutput ); // 1st method to test
guessAndEliminate ( answer, enableOutput ); // 2nd method to test
guessThreeThenEliminate ( answer, enableOutput ); // 3rd method to test
countOne = methodicalEliminate ( answer, enableOutput );
countTwo = guessAndEliminate ( answer, enableOutput );
countThree = guessThreeThenEliminate ( answer, enableOutput );
sumOne += countOne;
sumTwo += countTwo;
sumThree += countThree;
}
cout << "Methodical Eliminate required an average of " << (sumOne / 100 ) << " tries. " << endl;
cout << "Guess and Eliminate required an average of " << (sumTwo / 100 ) << " tries. " << endl;
cout << "Guess Three then Eliminate required an average of " << (sumThree / 100 ) << " tries. " << endl;
这些功能在该程序之上,但不应该是必要的,因为我知道这些是正确的。我测试了它们并且它们是正确的。这是我添加的唯一新代码,由于某种原因无法打印。它不会在for循环后打印3个cout语句。我觉得它因某种原因而陷入了这个循环中。