2014-09-29 18 views
-1
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.它需要有三個值才能讓我在while循環之外達到「已贏得匹配」字符串。任何幫助?如何轉義while循環? C++

+4

'NOTFOUND == TRUE' – 2014-09-29 18:21:10

+0

你聲明** ** NOTFOUND環以上,並將其設置爲一個初始值爲真? – Lakey 2014-09-29 18:22:06

+0

@Lakey它聲明爲函數的參數。 – Borgleader 2014-09-29 18:22:39

回答

1
while (notFound = true) 

應該是:

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

或者乾脆:

while (notFound)