Problems with a two dimensional array

This is a discussion on Problems with a two dimensional array within the C++ Programming forums, part of the General Programming Boards category; I am trying to work with a 2D array its 24 by 2. I am getting a error that says, ...

  1. #1
    Registered User
    Join Date
    Aug 2009
    Location
    Colorado Springs
    Posts
    1

    Problems with a two dimensional array

    I am trying to work with a 2D array its 24 by 2. I am getting a error that says, error C2109: subscript requires array or pointer type in VS2008. I am using 4 files, a global includes which is not important, the programs class header, and the driver/program main files. Here is my code I currently have and since I am a student in this language lets assume that if there is a better way out there I can't do that.

    - Class Header Code -
    Code:
    /*
    #include "global_includes.h"
    
    class MeteorLogics
    {
    	public:
    		MeteorLogics();
    		void GetTemperatures(int, int);
    		double ComputeAverageTemp(int, int);
    		void DisplayTempratures(int, int, double);
    		void ScreenPause();
    
    	private:
    		int Temperaturematrices[24][2];
    		int NumTempratures;
    		int hourdisplay;
    		double AverageTemp;
    		double HighTemp;
    		double LowTemp;
    		int row;
    		int column;
    };
    */
    - Diver File -
    Code:
     /*
    #include "global_includes.h"
    #include "meteor_logics.h"
    
    //BEGIN -- Class implementation
    //
    MeteorLogics::MeteorLogics()
    {
    	Temperaturematrices[24][2];
    	AverageTemp = 0;
    	HighTemp = 0;
    	LowTemp = 0;
    	row = 0;
    	column = 0;
    }
    
    void MeteorLogics::GetTemperatures(int Temperaturematrices, int NumTempratures)
    {
    		while (hourdisplay >= 0 && hourdisplay < 24 && hourdisplay != EOF)
    		{
    			for (hourdisplay = 0; hourdisplay < 24; hourdisplay ++)
    			{
    				cout << "Enter temprature recorded for" << hourdisplay << ":00" << endl;
    				cin >> Temperaturematrices[hourdisplay = 0][NumTempratures = 0];
    			}
    
    			cout << "If you are finished with todays entries hold down ctrl and press z on your keyboard" << endl;
    		}	
    }
    
    double MeteorLogics::ComputeAverageTemp(int, int)
    {
    
    
    }
    
    void MeteorLogics::DisplayTempratures(int, int, double)
    {
    
    
    }
    
    void MeteorLogics::ScreenPause()
    {
    
    }
    //
    //END -- Class implementation
    */
    The empty functions are just there for structure, thats just my style and they are declared already. Thanks for the help guys.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Soooooo many things wrong in so few lines.

    Temperaturematrices is a single int, not an array --- you said so right here:
    Code:
    void MeteorLogics::GetTemperatures(int Temperaturematrices, int NumTempratures)
    Theoretically you could access the member variables with something like this->, but it would be easier to just use a different name for the input variable, which you don't use anyway so I'm not sure why you've bothered.

    Also, whatever you were on when you typed this:
    Code:
    [hourdisplay = 0]
    you should probably consider getting off of.

  3. #3
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,428
    Perhaps consider learning basic syntax a little more?
    You aren't initializing your array - you are just accessing an out-of-bounds index.
    And the array syntax in GetTemperatures is just so way off.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. question about multidimensional arrays
    By richdb in forum C Programming
    Replies: 22
    Last Post: 02-26-2006, 08:51 AM
  2. problems finding the average of an array column
    By mrgeoff in forum C Programming
    Replies: 4
    Last Post: 04-18-2005, 11:49 PM
  3. Type and nontype parameters w/overloading
    By Mr_LJ in forum C++ Programming
    Replies: 3
    Last Post: 01-02-2004, 12:01 AM
  4. Merge sort please
    By vasanth in forum C Programming
    Replies: 2
    Last Post: 11-09-2003, 11:09 AM

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