Hello everyone.
I wrote this going through the c++ guys book.
It works fine but when I try to plug in anything above 2 billion
the program goes into some kind of endless loop.
The highest value of "i" I get to is 31 before it does this behavior.
Is there some kind of limit to how many numbers visual studio can handle?
Is it something wrong with my code?
#include "std_lib_facilities.h"
int square(int a);
double simpleCalculator();
double distances();
int main(){
while (1 == 1) {
int rice = 0;//for input
cout << "Input the number of rice you want\nthis calculator will tell you how many days it will take to get there following the peasent's method\n";
cin >> rice;//input amount of rice wanted
int totalRice = 0;//our counter
for (int i = 1; i > 0; i++) {
totalRice = pow(2, i - 1) + totalRice;//every day doubled 1..2..4..., old chinese tale
cout << i << " current total rice is " << totalRice << "\n";
if (totalRice >= rice) { cout << "it took " << i << " days to reach " << rice << "\n\n"; break; }//end if
if (i > 64) { cout << "64 is our limit\n\n"; break; }
}//end for
}//end while
return 0;
}
Maybe try long, or long long instead of int. Unfortunately there is always a limit even if you surf around the web and find the large number libraries.