Program not reading file input :?

This is a discussion on Program not reading file input :? within the C++ Programming forums, part of the General Programming Boards category; The following it code for my programming assignment with one problem that I know of and maybe some i don't....The ...

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    10

    Question Program not reading file input :?

    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 why so 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

  2. #2
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,591
    The best way to get help is to say what is wrong, not that something is wrong.
    Learn to debug, place couts throughout the program letting you know what's happening on the inside. When you see something go wrong, you'll at least know were the problem is, which makes fixing it a possibility.
    A class that doesn't overload all operators just isn't finished yet. -- SmugCeePlusPlusWeenie
    A year spent in artificial intelligence is enough to make one believe in God. -- Alan J. Perlis

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 02-02-2009, 06:27 AM
  2. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 03:44 PM
  3. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  4. Last program!!
    By buckwheat88 in forum C++ Programming
    Replies: 12
    Last Post: 01-17-2006, 11:31 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21