Reputation: 63
Below is the basic piece of code that I am trying to run
double h_a[9],h_b[2500],h_c[2704];
int r_a,c_a,r_b,c_b,r_c,c_c;
r_a = c_a = 3;
r_b = c_b = 50;
r_c = r_a + r_b - 1;
c_c = c_a + c_b - 1;
for(int i=0;i<(r_a*c_a);i++)
h_a = double(rand() % 50 + 1);
for(i=0;i<(r_b*c_b);i++)
h_b = rand() % 50 + 1;
It is showing me the following errors: 1. incompatible types in assignment of 'double' to 'double [9] 2. name lookup of 'i' changed for ISO 'for' scoping [-fpermissive]| 3. incompatible types in assignment of 'int' to 'double [2500]'
Help will be appreciated.
Upvotes: 0
Views: 87
Reputation: 11
You are assigning an array's name with a value, which is wrong. You can assign it to an element of the array. i is declared in first for loop. That's why it is not visible in second for loop. declare it before first loop starts.
Upvotes: 0
Reputation: 263637
h_a
and h_b
are arrays. You can't assign a value to an array, only to an element of an array.
Replacing
h_a = double(rand() % 50 + 1);
by
h_a[0] = double(rand() % 50 + 1);
and making a similar change in the assignment to h_b
would satisfy the compiler. I have no idea whether it would be correct.
You have two for
loops. The first defines the loop variable in the loop header; the second does not:
for (int i = blah; blah; blah) { ... }
for (i = blah; blah; blah) { ... }
The scope of the i
defined in the first loop is just the loop. It's not visible in the second loop. But in an old version of C++, the scope extended to the block enclosing the loop. Under those rules, it would have been legal. Apparently the compiler still recognizes the old rules. Change i = ...
in the second loop to int i = ...
. You'll then have two distinct variables, both named i
, one for each loop.
Upvotes: 1