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
mrperfect75000Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Svetlin_PanayotovCommented:
Here's your code with some fixes.Should work fine now :)

int main()
{
      using namespace std;
      long n;
      long k;
      double p,q,y;

      cin >> n ;
      cin >> p;

      //double b[n+1];
      double *b;
      b = new double[n+1];

      q = 1 - p;

      y = p/q;

      b[0] = pow(q,n);
      
      for (k = 1; k < n; k++)      //here you probably forgot k++
      {

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

      }


      return 0;
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mrperfect75000Author Commented:
thanks, i get one error now......do you know what it is?
error C2871: 'std' : does not exist or is not a namespace
0
mrperfect75000Author Commented:
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?
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

Svetlin_PanayotovCommented:
The only reason I can think of - if n = 1 :)
0
mrperfect75000Author Commented:
i set n = 9
0
mrperfect75000Author Commented:
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!!!
0
Svetlin_PanayotovCommented:
You're welcome :)
Happy coding :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual C++.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.