Multidimensional array

0 James Walker · June 19, 2014
Can someone help me. I am trying to make a c++ program that stores user input as multidimensional array but it isn't working.
Or just a c++ program that stores user input as normal array.

Post a Reply

Replies

Oldest  Newest  Rating
0 James Walker · June 23, 2014
Thank you very much . 
0 Daniel Collier · June 20, 2014
Hi, to create a multidimensional array you can use int **pointer or int [][]pointer, accessing them is the exact same just but you just have to use two numbers instead of one so pointer[0][0], im not exactly sure what you want to store in them because its in another language, as far as printing out the multidimensional array you can use a nested for loop, a loop inside a loop.


for(int y = 0; y < pointerY.size(); y++)
{
for (int x = 0; x < pointerX.size(); x++)
{
std::cout << "pointer at X: " << x << " and Y: << y << " equals: " << "pointer[y][x] << endl;
}
}


you would have to keep track of the size/ length of the array because there isnt a function do this, ie .size();

another option would be to use std::map where you can map two values of any type together;
-1 James Walker · June 20, 2014
#include <iostream>
using namespace std;
int main()
{
int *pointer = NULL;
cout << "Cite valorivrei sa introduci" << endl;
int input;
cin >> input;
pointer = new int[input];
int temp;
for (int counter = 0; counter < input; counter++)
{
cout << "Introdu valoarea " << counter + 1<< endl;
cin >> temp;
*(pointer + counter) = temp;


}
cout << "Valori pe care leai introdus sint " << endl;
for (int counter = 0; counter < input; counter++)
{
cout << counter+1<<" Valoarea este " << *(pointer + counter) << endl;

}
cin.get();
cin.get();
delete[]pointer;
return 0;


}


This is how i made a program that stores user input as normal array and then output the array, but i have no idea how make a program that does this for multidimensional array. 
+3 Mathias Frits Rørvik · June 19, 2014
What have you tried?

https://buckysroom.org/photos/users/90/resized/e30a5b53768e0263ec8c316f3db607a0.png
  • 1

C++

107,325 followers
About

Used in many types of software including music players, video games, and many large scale applications.

Links
Moderators
Bucky Roberts Administrator