Need help with creating arrays outiside functions

This is a discussion on Need help with creating arrays outiside functions within the C++ Programming forums, part of the General Programming Boards category; okay so straight out, i need my arrays and their size integer variable to be global functions, but my compiler ...

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    1

    Need help with creating arrays outiside functions

    okay so straight out, i need my arrays and their size integer variable to be global functions, but my compiler isn't accepting it. i use dev c++. so what do i do?

    Code:
    #include<iostream.h>
    
    using namespace std;
    
    int size;
    
    char Field[size][size];
    char Ground[size][size];
    
    void Diff()
    {
         char ch;
         
        cout<<"Please select a level of Difficulty:"<<endl;
        cout<<"E.Easy"<<endl;
        cout<<"M.Medium"<<endl;
        cout<<"D.Difficulty"<<endl;
        cout<<endl<<"Choice:";
        
        cin>>ch;
        
        if(ch=='E') size=9;
        if(ch=='M') size=17;
        if(ch=='D') size=25;
    }
    that's the code

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,303
    The size must be a compile time constant.

    You probably do not need to use global variables. I suggest that you use a std::vector that is passed by (const) reference as needed.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. creating a new record
    By Aisthesis in forum C++ Programming
    Replies: 3
    Last Post: 05-28-2009, 04:56 PM
  2. Arrays and Functions
    By KunoNoOni in forum Game Programming
    Replies: 12
    Last Post: 10-04-2005, 10:41 PM
  3. functions and arrays
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 03-14-2002, 09:57 AM
  4. 2D arrays with functions made easy
    By goran in forum C Programming
    Replies: 1
    Last Post: 09-17-2001, 01:08 PM
  5. elements of arrays; functions
    By sballew in forum C Programming
    Replies: 6
    Last Post: 09-03-2001, 02:48 AM

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