• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

someone godly at C helpz me please

nan means not a number. you probably have an invalid operation somewhere. like division by 0, log 0 or something
 
Your code is hideous. Try using the Attach Code feature (so we can see the indentation) and using variable names that actually mean something. Then maybe someone will read it.
 
Yeah, you get a problem when you take this path through your code:

int main()
{
double f;
double b;
double c = 1.0;
double pp = 0.6;
int coin;
int win = 0;
int n = 0;
int i;
int bet;

for (i = 0; i < N-1; i++)
{
c = log(c);
coin = rand() % 2;
if (pp > 0.5)
{

At the end of this part C = 0
Coin = some random number from 0 to 1 (let's say 1 in this case)
pp=.6

so we next go into this part

if (pp > 0.5)
{
bet = 1;
f = 2 * pp - 1;
b = f * c;
}

at the end of this section
bet = 1
f = 2 * pp -1 = .2
b = .2 * 0 = 0

Now if coin == 0 and bet == 1 (same error also happens if coin==1)
{
c -= b;
n++;
}

Which makes c = c -b = 0 - 0 = 0
N = 10000001


So when you go back through the for loop again at the beginning here:
c = log(c);
coin = rand() % 2;
if (pp > 0.5)

c = log(0) = - infinity

and there's your problem. You need to prevent your log(0) error with another case somewhere.


 
Woops... good thing I didn't go through the trouble of trying to fix the code. Just noticed that it was due yesterday. Sorry.
 
Back
Top