rice on chess table // long double way too small

There is an old story that the emperor wanted to thank the inventor of
the game of chess and asked the inventor to name his reward. The inventor
asked for one grain of rice for the first square, 2 for the second, 4
for the third, and so on, doubling for each of the 64 squares.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
using namespace std;

int main(){

	int rice, squares = 0;
	A:///////////////////////////////
	squares = 0;
	cout << "Enter number of rice to receive ";
	cin >> rice;

	for (long double i = 1; i < rice; i *= 2)
		squares++;
	squares++;
	cout << squares << " squares necessary " << endl;

	goto A;//////////////////////////

}


Everything works fine untill i enter 1e10. Than program starts spaming

Enter number of rice to receive 1 squares necessary
Enter number of rice to receive 1 squares necessary
Enter number of rice to receive 1 squares necessary
....
Enter number of rice to receive 1 squares necessary
Enter number of rice to receive 1 squares necessary
....


I thought that long double is supposed to handle way bigger numbers than this 1e10
Actually i cant also enter 1e3 what i think is suppsoed to be 1 * 10^3, works if i enter 1000 up to 1 000 000 000. If i add 1 more 0 it gives me
Enter number of rice to receive 1 squares necessary

Why cant i also enter just 1e3 or 1e6?
Last edited on
Whoops sry for this i see that i didnt change
int rice to long double rice
Last edited on
Topic archived. No new replies allowed.