const int npart = 500;
double x[npart], y[npart], z[npart];
bedheight of yaxis, ly=20, x_axis lx=20 and z_axis lz=20
int cell_height=4;
const int number_cell = 5;// (ly/cell_height);
int counter2[number_cell];
int cell_particle;
for (h=0;h<number_cell;h++)
{
counter2[h]=0;
}
for (i = 0; i < npart; i++)
{
//cell_particle=int(y[i]) % cell_height;
cell_particle= int(fmod (y[i],cell_height));
counter2[cell_particle]=counter2[cell_particle]+1;
}
cout<<"particle counter="<<counter2[j]<<" cell number="<<cell_particle<<" position="<<(y[j])<<endl;
sol_fract=counter2[i]*(Volume of particle/(lx*lz*cell_height));
Could you please tell why the counter2[cell_particle] and sol_fract is contain wrong value? I am waiting for your suggestion.
int number_cell=20;
int counter2[20];
double y[500];
int cell_height=4;
for (h=0;h<number_cell;h++)
{
counter2[h]=0;
}
for (i = 0; i < npart; i++)
{
cell_particle=int((y[i]) % cell_height);
counter2[cell_particle]=counter2[cell_particle]+1;
}
cout<<"particle counter="<<counter2[j]<<" cell number="<<cell_particle<<endl;
output: error: invalid operands of types ‘double’ and ‘double’ to binary ‘operator%
我怎樣才能從模的雙重價值整數多少?值得注意的是,y [i] = 4.5,8.9,6等我需要整數值放在counter2數組上,但問題在於轉換(錯誤消息是錯誤:類型'double'的無效操作數和'雙'到二進制'運算符%)。你能告訴我如何解決這個問題?
INT int_value =的static_cast(STD: :輪(float_value)); [已經在這裏回答](https://stackoverflow.com/a/16570752/4953089) –
VKadiyski