Hi, I am trying to do an easy division on an integer, trying to assign the value to a double and I assume this is wrong.
However, all other operation, such as *,+. sqrt, sin work on the integer, just not the division. Ironically, if I multiply with the reciprocal I do get exactly the result I am looking for. However, I feel I am doing something wrong here, trying to divide an integer to get a double.
Why is this division so different to all the other operations?
Here the code.
1. This one works, I get an array with values from 1 to 100.
int main ()
{
int j, m;
m=100;
double x[m];
for (j=0; j<m; j++)
{
x[j]=j*0.1;
cout << x[j] << endl;
}
}
However, my original does not work, or I should say I am surprised by what I see.
x[j]=j/10;
This yields an array with 10 times the 1, 10 times the 2 and so on.