Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-10-25
7
Medium Priority
?
1,824 Views
Last Modified: 2010-07-27
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
0
Comment
Question by:mrperfect75000
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 6

Accepted Solution

by:
Svetlin_Panayotov earned 260 total points
ID: 12407924
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
 

Author Comment

by:mrperfect75000
ID: 12411973
thanks, i get one error now......do you know what it is?
error C2871: 'std' : does not exist or is not a namespace
0
 

Author Comment

by:mrperfect75000
ID: 12412238
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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 6

Expert Comment

by:Svetlin_Panayotov
ID: 12412790
The only reason I can think of - if n = 1 :)
0
 

Author Comment

by:mrperfect75000
ID: 12413113
i set n = 9
0
 

Author Comment

by:mrperfect75000
ID: 12413387
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
 
LVL 6

Expert Comment

by:Svetlin_Panayotov
ID: 12418610
You're welcome :)
Happy coding :)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

597 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question