我完全不明白它有什麼問題。最後的嘗試次數是9,即使有一個while循環。我想檢查猜測是字符串中的座標之一,但它從來沒有工作。 :/字符串/數組情況C++
我在哪裏移動if語句?
int main() {
int guesses, destroy, numAttempts = 11;
string guess, i;
string coordinate[3] = {"B1", "C4", "D3"};
cout << "Enter in a coordinate between A-1 and D-4 (i.e. C4): ";
cin >> guess;
guesses = 0;
destroy = 0;
while (guess != coodinate[i] && guesses < numAttempts - 1) {
cout << "Target missed. Try again: ";
cin >> guess;
guesses++;;
}
if (guess != coordinate[i])
cout << "Failed!";
else
cout << "Congrats!";
/*if (guess == coordinate) {
cout << "Target hit! Next target: ";
cin >> guess;
destroy++;
guesses++;
}
*/
}
考慮到Bigood被打錯了,這是真的嗎? – StoryTeller 2013-04-28 16:37:39
'我'應該被聲明爲'int',而不是'string' ... – dreamlax 2013-04-28 17:27:26