Help with parallel array

Discussion in 'C++' started by psppb, Dec 30, 2007.

  1. psppb

    psppb New Member

    Joined:
    Dec 26, 2007
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    0
    Strait out of a book I am working on this and the compiler (Bloodshed Dev C++) will not accept it.

    The errors:
    18 C:\Documents and Settings\Bill\My Documents\parrallel array.cpp `planet' undeclared (first use this function)
    19 C:\Documents and Settings\Bill\My Documents\parrallel array.cpp `distance' undeclared (first use this function)
    38 C:\Documents and Settings\Bill\My Documents\parrallel array.cpp expected primary-expression before '=' token

    Can anyone find the problem why it will not take 'planet' and 'distance'??

    Thanks

    Code below.
    Code:
    #include <iostream.h>
    #include <string.h>
    
    #define length = 8
    #define max = 9
    
    #define TAB '\t'
    
    
        
    
    int main()
    {
        char planet[max][length];
        int distance[max];
        int index;
        //Initialize the two arrays
        strcpy(planet[0], "MERCURY" );
        distance[0] = 58;
        strcpy(planet[1], "VENUS" );
        distance[1] = 108;
        strcpy(planet[2], "EARTH" );
        distance[2] = 150;
        strcpy(planet[3], "MARS" );
        distance[3] = 228;
        strcpy(planet[4], "JUPITER" );
        distance[4] = 778;
        strcpy(planet[5], "SATURN" );
        distance[5] = 1427;
        strcpy(planet[6], "URANUS" );
        distance[6] = 2869;
        strcpy(planet[7], "NEPTUNE" );
        distance[7] = 4498;
        strcpy(planet[8], "PLUTO" );
        distance[8] = 5900;
        
        cout << TAB << TAB << "PLANET" << TAB << TAB << "DISTANCE" << endl << endl;
        for(index = 0; index < max; index++)
        {
                  cout << TAB << TAB <<planet[index];
                  cout << TAB << TAB <<distance[index] << endl;
                  }
                  cout << endl;
                  
                     cin.ignore(256, '\n');
              cout << "Press ENTER to continue..." << endl;
              cin.get();
              return 0;
              }
     
  2. NewsBot

    NewsBot New Member

    Joined:
    Dec 2, 2008
    Messages:
    1,267
    Likes Received:
    2
    Trophy Points:
    0
    You should define the #define as
    Code:
    #define length 8
    #define max 9
     
  3. psppb

    psppb New Member

    Joined:
    Dec 26, 2007
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    0
    You Rule! I did not see that after three hours!
     
  4. NewsBot

    NewsBot New Member

    Joined:
    Dec 2, 2008
    Messages:
    1,267
    Likes Received:
    2
    Trophy Points:
    0
    You just need fresh pair of eyes and nothing more than that.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice