I have difficulty to declare the following type of array.

1/36, (one divided 36)
2/36, (two dvided 36)
3/36,
4/36,
5/36,
6/36,
5/36,
4/36,
3/36,
2/36,
1/36

double exptRoll [arraySize] = { 1/36, 2/36, 3/36, 4/36, 5/36, 6/36, 5/36, 4/36, 3/36, 2/36, 1/36};

This doesn't work. Can someone tell me what the right way is?

All those values are integers. 1/36 = 0. 2/36 = 0. There is no decimal with integers.

So make the values real: 1.0/36.0 = some floating point value

All those values are integers. 1/36 = 0. 2/36 = 0. There is no decimal with integers.

So make the values real: 1.0/36.0 = some floating point value

when I have 3000 times (1.0 / 36.0), the result is 83.3

How can I only have the result 83 without .3 ?

Edited 4 Years Ago by chuyauchi: n/a

when I have 3000 times (1.0 / 36.0), the result is 83.3

How can I only have the result 83 without .3 ?

You can cast any float or double value to type int and you will lose any fractional part. Of course you will want to make sure that your result will be small enough to fit within an integer. A signed integer can hold a value as high as 2 billion plus some, or twice that for unsigned. For example:

double x = 83.3333
int result = 0;
result = static_cast<int>(x);

Now result equals only 83 since integers can only represent whole numbers.

This article has been dead for over six months. Start a new discussion instead.