Reputation: 265
I am trying to divide the items of an array with "1000", and I think my syntax is wrong, kindly help!
data[99] contains the values from 1-100 while two[99] is empty.
float two[99];
for(int x=0; x<100; x++)
{
two[x]=data[x]/1000;
}
Upvotes: 3
Views: 442
Reputation: 7673
You have a zero-based indexes array so you need:
float two[100];
for(int x=0; x<100; x++)
{
two[x]=(float)data[x]/(float)1000;
}
I added the (float) conversion to make sure you get the expected values, since we don't know the type of data[…].
Upvotes: 1
Reputation: 56479
Define two
like this:
float two[100]; // 99 + 1
Arrays start from 0
in C/C++, so two[99]
refers to 100th item of two
.
Upvotes: 4
Reputation: 258608
The syntax is okay, the logic is wrong. float two[99];
has 99
items - 0
through 98
- two[99]
is illegal.
Upvotes: 2