This is what is asked of me.
"Create a flowchart and write a complete C++ program that declares a 2 dimensional integer array of size 10 rows and 10 columns. The program should use two nested for loops to fill the array with the even numbers beginning with 2 in the [0][0] element and filling the first row with 2, 4, 6, 8, 10, 12, 14, 16, 18, 20 and then continuing on the second row with 22, 24, etc… The program should then use nested for loops to print the array in table form to the screen."
This is the code I have to fill the array (i think it works I have not ran it since I can't get it to print out).
//Michelle Stokes CSI130 Handout 10
//Arrays
#include <iostream>
using namespace std;
int main()
{
int ray[10][10], r, c, n;
for(r=0; r<=10; r++)
{
for(c=0; c<=10; c++)
{
n=2;
ray[r][c]=n;
n=n+2;
}
}
return 0;
}
my problem is, I can't figure out how to print the array in table form to the screen. I thought maybe something along these lines to get it to print...
for(r=0; r<=10; r++)
{
for(c=0; c<=10; c++)
{
cout << " " << ray[r][c];
}
}
But I don't think it looks right.
I ran it and got a screen full of twos and finally a debug error of "Run-Time Check Failure #2 - Stack around the variable 'ray' was corrupted.