hi guys i really need some help. Im trying to turn my index array into a multidimensional array and cant get it to compile. thanx for the help.

include <iostream>
using namespace std;
#include <cstdlib>
#include <cstring>
#include <iomanip>


const int LIMIT = 10;
const int MAX = 10;


class Matrixarray
{
private:
	double myarray[LIMIT][MAX];
public:
		void putel(int n,int j,int val)
{
		if (n <0 || n>=LIMIT)
		{
			cout << "OUT OF BOUNDS";
			myarray[n] = val;
		}
		if ( j <0 || j>=MAX)
		{
			cout << "OUT OF BOUNDS";
			myarray[j] = value;
		}
		double getel(int n, int j)const
		{
			if(n<0 || n>=LIMIT)
			{
				cout << "OUT OF BOUNDS";
				return myarray[n];
			}
			if(j<0 || j>=MAX)
			{
				cout << "OUT OF BOUNDS";
				return myarray[j];
			}
		}
	}
};


int main()
{
	Matrixarray ma1;
	for (int j=0; j<LIMIT; j++)
		ma1.putel(j, j*10);
	for (int j=0; j<LIMIT; j++)
	{
		int temp = ma1.getel(j);
		cout << "Your Element: " << j << "is" << temp << endl;
	}
	return 0;
}

Edited 6 Years Ago by Nick Evan: Put the closing CODE-tag at the end of the code

What are the compilation errors that you are getting?

Note that among other things, your call to the putel() method in main doesn't take the same number of parameters as it does in the class definition.

Also, with your out of bounds checks you place the element or return it even if it doesn't exist. This will give you nothing but problems down the line.

int cannot be converted to int[10] I looked up the error code and couldnt figure out what it meant.

myarray is a 2D array and you are trying to assign a single value to a row in 22 and 27, and return a row instead of a single value in 34 and 39. What is happening to that other dimension? myarray[m][n] is an integer, where m and n are in bounds.

This article has been dead for over six months. Start a new discussion instead.