We help IT Professionals succeed at work.
Get Started

Run-time Check Failure #2

trifecta2k asked
Last Modified: 2012-05-06
I'm new to C++ and my program works, but I keep getting the following error:

Run-time check failure #2 - stack around the variable "ranNumArray" was corrupted.

I'm not sure why this is happening, can some please help!  Thanks a lot.
int main (void)
int ranNumber;
int ranNumArray[100];
int i;
int numFind;
int arrayPos;
int foundNum = 0;
  /* initialize random seed: */
  srand (1);
  /* generate secret number: */
for(i=0; i< 101; i++) {
  ranNumber = rand() % 100 + 1;
  ranNumArray[i] = ranNumber;
  cout<<i<<" "<<ranNumArray[i]<<endl;	
     int max = ranNumArray[0]; 
     for(int i = 1; i<101; i++)
          if(ranNumArray[i] > max)
                max = ranNumArray[i];
 cout<<"The Max is "<<max<<endl;
 cout<<"Please enter a number to find:";
     for(int x = 0; x<101; x++)
          if(ranNumArray[x] == numFind) {
          		cout<<"The position of your number is "<<x<<endl;
                foundNum = 1;
  if(foundNum == 0){
  	cout<<"Not Found";
return 0; 

Open in new window

Watch Question
Top Expert 2009
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE