Link to home
Start Free TrialLog in
Avatar of mrperfect75000
mrperfect75000Flag for United States of America

asked on

Microsoft Visual C++ error error C2057,error C2133,error C2466

I'm writing very simple code for an array and i get this error...can anyone help? it seems to have to do with my array and the fact that i'm using "double"
 : error C2057: expected constant expression
 : error C2466: cannot allocate an array of constant size 0
 : error C2133: 'b' : unknown size


Here is my code ....what am i doing wrong?

#include <iostream.h>
#include <string.h>
#include <math.h>

int main()
{      

      long n;
      long k;
      double p,q,y;

            cin>> n ;
      cin>> p;

      double b[n+1];

      q = 1 - p;

      y = p/q;

                  b[0] = pow(q,n);

            for (k = 1; k < n;)
            {

                        b[k] = ((n-k+1)*b[k-1]* y )/ k;

            }
            

            return 0;
}


thank you
ASKER CERTIFIED SOLUTION
Avatar of Svetlin_Panayotov
Svetlin_Panayotov

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mrperfect75000

ASKER

thanks, i get one error now......do you know what it is?
error C2871: 'std' : does not exist or is not a namespace
thanx a lot - i fixed that......one last question....for some reason it doesnt loop thru K ...gives me just one out put when i cout<<b[k] any ideas?
Avatar of Svetlin_Panayotov
Svetlin_Panayotov

The only reason I can think of - if n = 1 :)
i set n = 9
Hey thanks i got it...i commented out namespace std becos this problem is caused because certain header files (such as cstdlib and cassert do not declare the std namespace in VC++ 6.0.

i wasnt gettin good results because i should have put the cout in the loop.
thanks a lot!!!
You're welcome :)
Happy coding :)