如何逃脱while循环? C ++

时间:2014-09-29 18:19:41

标签: c++

void fireShip1(int Numbers2[], bool notFound, int position1, string playerOne, int numberOfSunkenShips, int numberOfShips)
{
    numberOfSunkenShips = 0;
    while (notFound = true)
    {
        cout << playerOne << ", please enter a location to fire at." << endl;
        cin >> position1;
            if (Numbers2[position1] == 0)
            {
                cout << "You missed!" << endl;
            }
            else if (Numbers2[position1] == 1)
            {
                cout << "Bullseye!" << endl;
                numberOfSunkenShips++;
                cout << "You have sunk " << numberOfSunkenShips << " ships." << endl;
                if (numberOfSunkenShips == numberOfShips)
                {
                    notFound = false;
                }
                Numbers2[position1] = 0;
                return;
            }
    }
    cout << playerOne << " has won the match!" << endl;
}

numberofSunkenShips不会高于1.它需要具有值3才能使我在while循环之外达到“赢得匹配”字符串。有什么帮助吗?

1 个答案:

答案 0 :(得分:1)

while (notFound = true)

应该是:

//assume you have declared notFound
while (notFound == true)
              //^^^

或简单地说:

while (notFound)