// Lab9-ConvertToStruct-Buggy.cpp // based on advenand.cpp from textbook #include // for cin and cout #include // to use the string class to input name using namespace std; // several C++ systems are clustered in the std:: namespace, this line simplifies using those systems void main(); { cout << "Welcome to Godzilla's Revenge\n"; int nPlayerX = 10; int nPlayerY = 10; string sPlayerName; cout << "What's your name? "; cin >> sPlayerName; int nTreasureX = 7; int nTreasureY = 11; char cDirection = 'a'; while (cDirection == 'q') { cout << endl << sPlayerName << ", your location is " << nPlayerX << ", " << nPlayerY; cout << "\nEnter direction (n, s, e, w). Use 'q' to Quit: "; cDirection = _getche(); // get direction switch(cDirection) { case 'n': nPlayerY--; break; // update coordinates case 's': nPlayerY++; break; case 'e': nPlayerX++; break; case 'w': nPlayerX--; break; } // end switch(cDirection) if (nPlayerX==nTreasureX || nPlayerY==nTreasureY) { // if player has landed on same coordinate as Treasure cout << "\nYou found the treasure!\n"; break; // terminates execution of the current loop } // end while (cDirection != 'q') } // end main