# chess board grain counter [int and double]

Bjarne Stroustrup “Programming Principles and Practice Using C++”
Chapter 4 Exercise 9
Using std_lib_facilities.h by Bjarne Stroustrup.

```//	Philipp Siedler
//	Bjarne Stroustrup's PP
//	Chapter 4 Exercise 9

#include "std_lib_facilities.h"

int main() {

cout << "Grains on chess board as integers: \n\n";
int squareNumi = 1;
int grainCounti = 1;
int sumGrainCounti = 0;

for (int i = 1; i < 65; i++) {
squareNumi = i;
grainCounti *= 2;
sumGrainCounti += grainCounti;

cout << "Square number: " << squareNumi << " / Grain number on square: " << grainCounti << " / Total grain number: " << sumGrainCounti << '\n';
}

cout << "\n\nGrains on chess board as integers: \n\n";
double squareNumd = 1;
double grainCountd = 1;
double sumGrainCountd = 0;

for (int i = 1; i < 65; i++) {
squareNumd = i;
grainCountd *= 2;
sumGrainCountd += grainCountd;

cout << "Square number: " << squareNumd << " / Grain number on square: " << grainCountd << " / Total grain number: " << sumGrainCountd << '\n';
}

keep_window_open(".");

}
```
```Output:
Grains on chess board as integers:

Square number: 1 / Grain number on square: 2 / Total grain number: 2
Square number: 2 / Grain number on square: 4 / Total grain number: 6
Square number: 3 / Grain number on square: 8 / Total grain number: 14
Square number: 4 / Grain number on square: 16 / Total grain number: 30
Square number: 5 / Grain number on square: 32 / Total grain number: 62
Square number: 6 / Grain number on square: 64 / Total grain number: 126
Square number: 7 / Grain number on square: 128 / Total grain number: 254
Square number: 8 / Grain number on square: 256 / Total grain number: 510
Square number: 9 / Grain number on square: 512 / Total grain number: 1022
Square number: 10 / Grain number on square: 1024 / Total grain number: 2046
Square number: 11 / Grain number on square: 2048 / Total grain number: 4094
Square number: 12 / Grain number on square: 4096 / Total grain number: 8190
Square number: 13 / Grain number on square: 8192 / Total grain number: 16382
Square number: 14 / Grain number on square: 16384 / Total grain number: 32766
Square number: 15 / Grain number on square: 32768 / Total grain number: 65534
Square number: 16 / Grain number on square: 65536 / Total grain number: 131070
Square number: 17 / Grain number on square: 131072 / Total grain number: 262142
Square number: 18 / Grain number on square: 262144 / Total grain number: 524286
Square number: 19 / Grain number on square: 524288 / Total grain number: 1048574
Square number: 20 / Grain number on square: 1048576 / Total grain number: 2097150
Square number: 21 / Grain number on square: 2097152 / Total grain number: 4194302
Square number: 22 / Grain number on square: 4194304 / Total grain number: 8388606
Square number: 23 / Grain number on square: 8388608 / Total grain number: 16777214
Square number: 24 / Grain number on square: 16777216 / Total grain number: 33554430
Square number: 25 / Grain number on square: 33554432 / Total grain number: 67108862
Square number: 26 / Grain number on square: 67108864 / Total grain number: 134217726
Square number: 27 / Grain number on square: 134217728 / Total grain number: 268435454
Square number: 28 / Grain number on square: 268435456 / Total grain number: 536870910
Square number: 29 / Grain number on square: 536870912 / Total grain number: 1073741822
Square number: 30 / Grain number on square: 1073741824 / Total grain number: 2147483646
Square number: 31 / Grain number on square: -2147483648 / Total grain number: -2
Square number: 32 / Grain number on square: 0 / Total grain number: -2
Square number: 33 / Grain number on square: 0 / Total grain number: -2
Square number: 34 / Grain number on square: 0 / Total grain number: -2
Square number: 35 / Grain number on square: 0 / Total grain number: -2
Square number: 36 / Grain number on square: 0 / Total grain number: -2
Square number: 37 / Grain number on square: 0 / Total grain number: -2
Square number: 38 / Grain number on square: 0 / Total grain number: -2
Square number: 39 / Grain number on square: 0 / Total grain number: -2
Square number: 40 / Grain number on square: 0 / Total grain number: -2
Square number: 41 / Grain number on square: 0 / Total grain number: -2
Square number: 42 / Grain number on square: 0 / Total grain number: -2
Square number: 43 / Grain number on square: 0 / Total grain number: -2
Square number: 44 / Grain number on square: 0 / Total grain number: -2
Square number: 45 / Grain number on square: 0 / Total grain number: -2
Square number: 46 / Grain number on square: 0 / Total grain number: -2
Square number: 47 / Grain number on square: 0 / Total grain number: -2
Square number: 48 / Grain number on square: 0 / Total grain number: -2
Square number: 49 / Grain number on square: 0 / Total grain number: -2
Square number: 50 / Grain number on square: 0 / Total grain number: -2
Square number: 51 / Grain number on square: 0 / Total grain number: -2
Square number: 52 / Grain number on square: 0 / Total grain number: -2
Square number: 53 / Grain number on square: 0 / Total grain number: -2
Square number: 54 / Grain number on square: 0 / Total grain number: -2
Square number: 55 / Grain number on square: 0 / Total grain number: -2
Square number: 56 / Grain number on square: 0 / Total grain number: -2
Square number: 57 / Grain number on square: 0 / Total grain number: -2
Square number: 58 / Grain number on square: 0 / Total grain number: -2
Square number: 59 / Grain number on square: 0 / Total grain number: -2
Square number: 60 / Grain number on square: 0 / Total grain number: -2
Square number: 61 / Grain number on square: 0 / Total grain number: -2
Square number: 62 / Grain number on square: 0 / Total grain number: -2
Square number: 63 / Grain number on square: 0 / Total grain number: -2
Square number: 64 / Grain number on square: 0 / Total grain number: -2

Grains on chess board as integers:

Square number: 1 / Grain number on square: 2 / Total grain number: 2
Square number: 2 / Grain number on square: 4 / Total grain number: 6
Square number: 3 / Grain number on square: 8 / Total grain number: 14
Square number: 4 / Grain number on square: 16 / Total grain number: 30
Square number: 5 / Grain number on square: 32 / Total grain number: 62
Square number: 6 / Grain number on square: 64 / Total grain number: 126
Square number: 7 / Grain number on square: 128 / Total grain number: 254
Square number: 8 / Grain number on square: 256 / Total grain number: 510
Square number: 9 / Grain number on square: 512 / Total grain number: 1022
Square number: 10 / Grain number on square: 1024 / Total grain number: 2046
Square number: 11 / Grain number on square: 2048 / Total grain number: 4094
Square number: 12 / Grain number on square: 4096 / Total grain number: 8190
Square number: 13 / Grain number on square: 8192 / Total grain number: 16382
Square number: 14 / Grain number on square: 16384 / Total grain number: 32766
Square number: 15 / Grain number on square: 32768 / Total grain number: 65534
Square number: 16 / Grain number on square: 65536 / Total grain number: 131070
Square number: 17 / Grain number on square: 131072 / Total grain number: 262142
Square number: 18 / Grain number on square: 262144 / Total grain number: 524286
Square number: 19 / Grain number on square: 524288 / Total grain number: 1.04857e+06
Square number: 20 / Grain number on square: 1.04858e+06 / Total grain number: 2.09715e+06
Square number: 21 / Grain number on square: 2.09715e+06 / Total grain number: 4.1943e+06
Square number: 22 / Grain number on square: 4.1943e+06 / Total grain number: 8.38861e+06
Square number: 23 / Grain number on square: 8.38861e+06 / Total grain number: 1.67772e+07
Square number: 24 / Grain number on square: 1.67772e+07 / Total grain number: 3.35544e+07
Square number: 25 / Grain number on square: 3.35544e+07 / Total grain number: 6.71089e+07
Square number: 26 / Grain number on square: 6.71089e+07 / Total grain number: 1.34218e+08
Square number: 27 / Grain number on square: 1.34218e+08 / Total grain number: 2.68435e+08
Square number: 28 / Grain number on square: 2.68435e+08 / Total grain number: 5.36871e+08
Square number: 29 / Grain number on square: 5.36871e+08 / Total grain number: 1.07374e+09
Square number: 30 / Grain number on square: 1.07374e+09 / Total grain number: 2.14748e+09
Square number: 31 / Grain number on square: 2.14748e+09 / Total grain number: 4.29497e+09
Square number: 32 / Grain number on square: 4.29497e+09 / Total grain number: 8.58993e+09
Square number: 33 / Grain number on square: 8.58993e+09 / Total grain number: 1.71799e+10
Square number: 34 / Grain number on square: 1.71799e+10 / Total grain number: 3.43597e+10
Square number: 35 / Grain number on square: 3.43597e+10 / Total grain number: 6.87195e+10
Square number: 36 / Grain number on square: 6.87195e+10 / Total grain number: 1.37439e+11
Square number: 37 / Grain number on square: 1.37439e+11 / Total grain number: 2.74878e+11
Square number: 38 / Grain number on square: 2.74878e+11 / Total grain number: 5.49756e+11
Square number: 39 / Grain number on square: 5.49756e+11 / Total grain number: 1.09951e+12
Square number: 40 / Grain number on square: 1.09951e+12 / Total grain number: 2.19902e+12
Square number: 41 / Grain number on square: 2.19902e+12 / Total grain number: 4.39805e+12
Square number: 42 / Grain number on square: 4.39805e+12 / Total grain number: 8.79609e+12
Square number: 43 / Grain number on square: 8.79609e+12 / Total grain number: 1.75922e+13
Square number: 44 / Grain number on square: 1.75922e+13 / Total grain number: 3.51844e+13
Square number: 45 / Grain number on square: 3.51844e+13 / Total grain number: 7.03687e+13
Square number: 46 / Grain number on square: 7.03687e+13 / Total grain number: 1.40737e+14
Square number: 47 / Grain number on square: 1.40737e+14 / Total grain number: 2.81475e+14
Square number: 48 / Grain number on square: 2.81475e+14 / Total grain number: 5.6295e+14
Square number: 49 / Grain number on square: 5.6295e+14 / Total grain number: 1.1259e+15
Square number: 50 / Grain number on square: 1.1259e+15 / Total grain number: 2.2518e+15
Square number: 51 / Grain number on square: 2.2518e+15 / Total grain number: 4.5036e+15
Square number: 52 / Grain number on square: 4.5036e+15 / Total grain number: 9.0072e+15
Square number: 53 / Grain number on square: 9.0072e+15 / Total grain number: 1.80144e+16
Square number: 54 / Grain number on square: 1.80144e+16 / Total grain number: 3.60288e+16
Square number: 55 / Grain number on square: 3.60288e+16 / Total grain number: 7.20576e+16
Square number: 56 / Grain number on square: 7.20576e+16 / Total grain number: 1.44115e+17
Square number: 57 / Grain number on square: 1.44115e+17 / Total grain number: 2.8823e+17
Square number: 58 / Grain number on square: 2.8823e+17 / Total grain number: 5.76461e+17
Square number: 59 / Grain number on square: 5.76461e+17 / Total grain number: 1.15292e+18
Square number: 60 / Grain number on square: 1.15292e+18 / Total grain number: 2.30584e+18
Square number: 61 / Grain number on square: 2.30584e+18 / Total grain number: 4.61169e+18
Square number: 62 / Grain number on square: 4.61169e+18 / Total grain number: 9.22337e+18
Square number: 63 / Grain number on square: 9.22337e+18 / Total grain number: 1.84467e+19
Square number: 64 / Grain number on square: 1.84467e+19 / Total grain number: 3.68935e+19```

This site uses Akismet to reduce spam. Learn how your comment data is processed.