Hi all,
As a newbie, I'm still teaching myself the C++ language, and having a bit of trouble finding exactly where my error is. The program builds just fine, It runs just fine, however, at the end of the run, when I exit the program I get the following error.
1 2
Run Tine Check Failure #2 - Stack around variable 'thirdball' was corrupted.
and I cannot find where the error is. Any help would be greatly appreciated. The part of my code wherein the error lies is:
if(userinput == 2) // checks to see if a user inputed a set of numbers that has ever won the Megamoney lotto
{
cout<<"You have chosen to check if your set of numbers has ever won Megamoney Lotto."<<endl<<endl;
cout<<"Please enter the first number and press enter "<<endl<<endl;
cin>>firstball;
cout<<"Please enter the second number and press enter "<<endl<<endl;
cin>>secondball;
cout<<"Please enter the third number and press enter "<<endl<<endl;
cin>>thirdball;
cout<<"Please enter the fourth number and press enter "<<endl<<endl;
cin>>fourthball;
cout<<"Please enter the MegaBall and press enter "<<endl<<endl<<endl;
cin>>megaball;
for(int i = 0; i < Vec_Count; i++)
{
if(Data[i].m_Powerball == megaball)
{
if(Data[i].m_First == firstball || Data[i].m_First == secondball ||
Data[i].m_First == thirdball || Data[i].m_First == fourthball)
if(Data[i].m_Second == firstball || Data[i].m_Second == secondball ||
Data[i].m_Second == thirdball || Data[i].m_Second == fourthball)
if(Data[i].m_Third == firstball || Data[i].m_Third == secondball ||
Data[i].m_Third == thirdball || Data[i].m_Third == fourthball)
if(Data[i].m_Fourth == firstball || Data[i].m_Fourth == secondball ||
Data[i].m_Fourth == thirdball || Data[i].m_Fourth == fourthball)
{
cout<<"Yes!! your chosen numbers won the lotto on: "
<<Data[i].m_Month<<" "<<Data[i].m_Day;
if(Data[i].m_Year>12)
cout<<" "<< Data[i].m_Year+1900<<endl<<endl;
else
cout<<" "<<Data[i].m_Year+2000<<endl<<endl<<endl;
foundmatch=1;
break;
}
}
} // end for loop
if(!foundmatch)
cout<<"Sorry, those numbers you chose have NEVER won the lotto."<<endl<<endl;
foundmatch=0; // reset foundmatch. Note: it resets it independent of the preceeding if statement!
} //end if (userinput==2)
//===================== Begin user input 2 ==========================================================================
if(userinput == 2) // checks to see if a user inputed set of numbers has ever won the Megamoney lotto
{
cout<<"You have chosen to check if your set of numbers has ever won Megamoney Lotto."<<endl<<endl;
cout<<"Please enter the first number and press enter "<<endl<<endl;
cin>>firstball;
cout<<"Please enter the second number and press enter "<<endl<<endl;
cin>>secondball;
cout<<"Please enter the third number and press enter "<<endl<<endl;
cin>>thirdball;
cout<<"Please enter the fourth number and press enter "<<endl<<endl;
cin>>fourthball;
cout<<"Please enter the MegaBall and press enter "<<endl<<endl<<endl;
cin>>megaball;
for(int i=0;i<Vec_Count;i++)
{
if(Data[i].m_Powerball == megaball)
{
if(Data[i].m_First == firstball || Data[i].m_First == secondball ||
Data[i].m_First == thirdball || Data[i].m_First == fourthball)
if(Data[i].m_Second == firstball || Data[i].m_Second == secondball ||
Data[i].m_Second == thirdball || Data[i].m_Second == fourthball)
if(Data[i].m_Third == firstball || Data[i].m_Third == secondball ||
Data[i].m_Third == thirdball || Data[i].m_Third == fourthball)
if(Data[i].m_Fourth == firstball || Data[i].m_Fourth == secondball ||
Data[i].m_Fourth == thirdball || Data[i].m_Fourth == fourthball)
{
cout<<"Yes!! your chosen numbers won the lotto on: "
<<Data[i].m_Month<<" "<<Data[i].m_Day;
if(Data[i].m_Year>12)
cout<<" "<< Data[i].m_Year+1900<<endl<<endl;
else
cout<<" "<<Data[i].m_Year+2000<<endl<<endl<<endl;
foundmatch=1;
break;
}
}
} // end for loop
if(!foundmatch)
cout<<"Sorry, those numbers you chose have NEVER won the lotto."<<endl<<endl;
foundmatch=0; // reset foundmatch. Note: it resets it independent of the preceeding if statement!
} //end if (userinput==2)
// This part of the program deals only with MegaMoney Lottery
#include <stdio.h> // printf
#include <ctype.h> // isalpha isdigit, isspace etc
#include <iostream> // cout, cin
#include <fstream>
#include <string>
#include <ios>
#include <stdlib.h>
#include <stddef.h>
#include <vector>
usingnamespace std;
class LotteryNumbers // creates a class called LotteryNumbers
{
public:
int m_Month;
int m_Day;
int m_Year;
int m_First;
int m_Second;
int m_Third;
int m_Fourth;
int m_Powerball;
// constructor function
LotteryNumbers ()
{
m_Month = 0;
m_Day = 0;
m_Year = 0;
m_First = 0;
m_Second = 0;
m_Third = 0;
m_Fourth = 0;
m_Powerball = 0;
} // close constructor
}; // close class definition
#define FALSE 0
#define TRUE 1
int main()
{
vector<LotteryNumbers> Data; //instantiate an object of the LotteryNumbers class and call it Data.
//Thus, Data is a vector of LotteryNumber Objects
vector<char> RawData; //Create a vector of characters, call it RawData. RawData will hold every single
//character from the raw data file, so that the program can analzye them.
char mychar=' '; //various variables used in the program
int CharCount = 0;
int Vec_Count = 0;
char anykey='a';
int userinput=0;
int month_key=0;
int day_key=0;
int year_key=0;
int foundmatch=0;
int firstball=0;
int secondball=0;
int thirdball=0;
int fourthball=0;
int megaball=0;
int frequencies[45]; //an array which will be used to hold the number of times each number is picked.
for(int i = 0; i < 45; i++)
frequencies[i]=0;
int megafreq[32]; //an array which will be used to hold the number of times each Megaball number is picked.
for(int i = 0; i < 32; i++)
megafreq[i]=0;
//Opens Temp_Program for reading the file
ifstream a_file ( "C:\\tmci\\RawData.txt" );
if (!a_file )
{
cout << "Can't open input file" << " RawData.txt " << endl << endl;
cin.get();
cin.ignore(1);
exit(1);
} // close ifstream
//================== The following is Loading RawData into a Vector (not an array)=================================
for( int i = 0; a_file; i++) //this loads every single character from RawData.txt into the vector of characters
// named RawData. It also count the number of characters in the RawData file.
{
RawData.push_back(mychar);
a_file >> RawData[i];
CharCount++;
}// end for loop to load in the Raw Data
//========================This ends Loading RawData into a Vector ==============================
//===============================================================================
for(int i=0;i<30;i++)
RawData.push_back(mychar); //add these blanks at the end to avoid overrun when examing the vector
CharCount=CharCount+30; //increment CharCount to account for the blanks we added at the end of the file