The following it code for my programming assignment with one problem that I know of and maybe some i don't....The problem I'm asking for help with is getting it to read the file input to use as commands, but I'm having no luck and i don't know whyso any help as to figuring out this problem would be greatly appreciated
:
Code:#include <cstdlib> #include <iostream> #include <fstream> #include <iomanip> using namespace std; const int COLS = 30; const int ROWS = 30; const int LIMIT =15; void moveTurtle(int turtle[][COLS]); void DrawFloor(int floor[][COLS]); void Move(int floor[][COLS],int, int, bool,int&, int&); int main(){ int turtleGride[ROWS][COLS]; moveTurtle(turtleGride); system("PAUSE"); }//end main void moveTurtle(int Turtle[][COLS]){ //1 ifstream infile; infile.open("turtle.dat"); bool pen = false; int Face = 1, command, floor[ROWS][COLS] = {0}, x, y; for(int j = 0; j < LIMIT ; j++){ //2 while (infile >> command && !infile.eof()){ //3 cout << command <<endl; switch(command){ //4 case 1: pen = false; break; case 2: pen = true; break; case 3: Face++; Face = Face%4; break; case 4: Face--; Face = (Face < 0 ? 4: Face); break; case 5: int steps; infile.ignore(); infile >> steps; Move(floor, Face, steps, pen, x, y); break; case 6: DrawFloor(floor); break; } } } } void Move(int floor[][COLS], int Face, int steps, bool pen, int &x, int &y){ for (int i = 0; i<steps; i++){ if(Face == 1){ if(pen==1) floor[y][x]=1; x++; }// end if else if(Face == 2){ if(pen==1) floor[y][x]=1; y++; }// end if else if(Face == 3){ if(pen==1) floor[y][x]=1; x--; }// end if else if(Face == 4){ if(pen==1) floor[y][x]=1; y++; }// end if }// end for }// end move void DrawFloor(int floor[][COLS]){ for (int i = 0; i < ROWS; i++){ for(int j = 0; j < COLS; j++) if (floor[j][i]) cout << "*"; else cout << " "; cout << endl; }// end outside for }// end drawfloor



LinkBack URL
About LinkBacks
so any help as to figuring out this problem would be greatly appreciated
:


