mrperfect75000
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
: 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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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?
The only reason I can think of - if n = 1 :)
ASKER
i set n = 9
ASKER
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!!!
i wasnt gettin good results because i should have put the cout in the loop.
thanks a lot!!!
You're welcome :)
Happy coding :)
Happy coding :)
ASKER
error C2871: 'std' : does not exist or is not a namespace