Oct 28, 2013 at 3:36pm Oct 28, 2013 at 3:36pm UTC
I'm trying to code a 20x20 array, filled with zeros. I keep getting an error C2109 saying that my [i] in the loop meant to fill the array must be a pointer-to-object type. What does this mean and how can I fix it?
#include <iostream>
#include<iomanip>
#include <cmath>
#include <ctime>
#include<string>
using namespace std;
const int columns=20;
const int rows=20;
int main()
{
int rowplaceholder=20;
int hotplate [rows][columns];
for (int i=0; i<20; i++)
{rowplaceholder [i] = 0;
cout<<i;
}
system("PAUSE");
return 0;
}
Oct 28, 2013 at 3:44pm Oct 28, 2013 at 3:44pm UTC
a) code tags.
b) each rows cell is a * to an array of ints so your type mismatching. you need to have another nested for loop and use it to iterate over columns
Oct 28, 2013 at 3:44pm Oct 28, 2013 at 3:44pm UTC
Please use code tags. You can get them by pressing the <> button to the right of the text box.
When you do this: rowplaceholder[i]
you're getting an array out of it, and you can't assign a scalar value to an array trivially.
You'll probably need a second loop to iterate through that array as well.
EDIT: Ninja'd.
EDIT2: And cire also has a good point.
-Albatross
Last edited on Oct 28, 2013 at 4:36pm Oct 28, 2013 at 4:36pm UTC
Oct 28, 2013 at 4:35pm Oct 28, 2013 at 4:35pm UTC
In addition to what's been posted before, presumably you meant to replace rowplaceholder[i]
in the body of the for loop with hotplate[i]
.
int hotplate[rows][columns] = {} ;
would also work to zero the array elements.
Last edited on Oct 28, 2013 at 4:35pm Oct 28, 2013 at 4:35pm UTC