I'm working on credit.c in pset1, and I've decided to implement a "get length" method that I'm testing. I think my logic is sound, but I'm getting an infinite loop when running the following code:
#include <stdio.h>
#include <cs50.h>
int main(void)
{
long long cnum = 378282246310005;
long long length = 0;
for(long long i = 0; (((10^i)-cnum) < 0); i++)
{
length = i;
}
printf("%lli\n", length);
}
The logic goes that, at 15 loops, 10^14-378282246310005 is negative, and 10^15-378282246310005 is positive. So it should exit the loop when i is 15, but it's instead looping infinitely. Any idea why that might be?