/** roomba.cpp 22-feb-2009/sklar this program simulates a robot wandering around a room. */ #include using namespace std; /** * main function * */ int main() { // declare variables int x; // robot's x position int y; // robot's y position char c; // user's input bool q; // does user want to quit? // initialize variables x = 0; y = 0; q = false; // loop until user enters Q to quit while ( q==false ) { cout << "the roomba is at location (" << x << "," << y << ")\n"; cout << "which way should roomba move (enter F,B,L,R or Q)? "; cin >> c; cout << "you entered: " << c << "\n"; if ( c=='F' ) { y = y + 1; } else if ( c=='B' ) { y = y - 1; } else if ( c=='L' ) { x = x - 1; } else if ( c=='R' ) { x = x + 1; } else if ( c=='Q' ) { q = true; } else { cout << "oops! you entered something invalid. please try again :-)\n"; } } // end while q==false } // end of main()