//---------------------------------------------------------------------- // // roombaCommand.cpp // // This program simulates a robot wandering around a room where the robot // is controlled by commands loaded from a file. // // Written by: Elizabeth Sklar // Modified by: Simon Parsons // // Last modified: 4th October #include #include using namespace std; int main() { // Set up input stream. ifstream myInput; // 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 --- I'll use the one generated by roombaLog.cpp myInput.open("log.txt"); myInput >> c; // Loop until user enters Q to quit or we reach the end of the file. while ( q==false && ! myInput.eof()) { cout << "the roomba is at location (" << x << "," << y << ")" << endl; cout << "reading a command from the file" << endl; cout << "the command is: " << 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; } // Read the next input myInput >> c; } // end while // Close the file myInput.close(); } // end of main()