Shift contents of array using parameters in C++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Shift contents of array using parameters in C++

Hello, I have been playing around with a bit of code for the past few weeks. The code is a display of the number 1. I want to essentially create a dot matrix style print out, where the 1 is continuously shifted to the right. Here is where I am so far: #include <iostream> using namespace std; /* use function to shift all characters one place to the right */ /* use a function to declare the characters of the fiqure */ int i, j; int matrix([int i][int j]); //dont think this is right

16th Nov 2016, 8:11 AM
Tony Robinson
Tony Robinson - avatar
2 Answers
0
first of all, you cannot declare the size of an array with a non-constant variable. this is unacceptable: int i = 3; int j = 3; int Matrix[i][j]; //won't compile but you can do: const int M = 3; const int N = 3; int Matrix[M][N] //cimpiles just fine if you really need variable matrix size (maybe the size is not known at compile time, only at runtime), then you should allot the array on the heap using malloc (you should study this along with pointers - useful topics to know). Second, you should always start small. why not try to implement your algorithm with a simple one-dimensional array first, before trying multidimensional. I could try the one for a simple array just to encourage you (will probably do that tomorrow).
18th Nov 2016, 9:42 PM
Rill Chritty
Rill Chritty - avatar
0
I meant allocate not allot
18th Nov 2016, 9:44 PM
Rill Chritty
Rill Chritty - avatar