//---------------------------------------------------------------------- // // roombaLog.cpp // // This program simulates a robot wandering around a room and logs the // movements that the robot makes. // // Written by: Elizabeth Sklar // Modified by: Simon Parsons // // Last modified: 15th September #include #include using namespace std; int main() { // Set up output stream. ofstream myOutput; // 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; // Open file myOutput.open("log.txt"); // Loop until user enters Q to quit while ( q==false ) { cout << "the roomba is at location (" << x << "," << y << ")" << endl; 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' ) || ( c == 'q' )) { q = true; } else { cout << "Oops! you entered something invalid. please try again :-)" << endl; } // Log the input myOutput << c; } // end while q==false // Close the file myOutput.close(); } // end of main()