I need to print an int array that has 50 values the array must contain multiple rows and each row can't have any more than 15 variables on it. Can any one point me in the right direction or explain where I'm going wrong?
#include <iostream>
using namespace std;
int main()
{
int alhpa[51];
for(int i = 0; i < 51; i++)
{
alpha[i] = -1; // initializes all elements to -1
}
for(int i = 0; i < 51; i++)
{
for(int j = 0; j < 15; j++)
{
cout << alpha[j] << "\t";
}
cout << endl;
}
return 0;
}
So the above code works it just doesn't do what I intended it to, if you run this you'll see that the array is printed in rows and each row does have 15 variables on it. How ever the issue is that it only prints the first 15 elements in the array and each time the main loop executes the process is reset and as I said above the only output is the first 15 variables over and over again.
I need to figure out how to print this array out in the same way it's printing now but I need all the elements in the array to be processed and printed.
I know that the last line wouldn't have 15 on it because there should only be room for 5 because 15 * 3 = 45
Any help would be awesome!
forloop (withifrom 0 to 50) that counts how many times you output an element and each time it reaches 15, output a newline and reset the counter.i.