Can someone tell me why while i'm adding units to this coreArray, the program pauses. Here's it is:
__________________________________________________________________
#ifndef LOTTOCLASS_H_INCLUDED
#define LOTTOCLASS_H_INCLUDED
using namespace std;
template<typename T>
class Lottery
{
public:
void Swap(T&a, T&b);
void arrRef(int num);
void createArray(int n);
int varArrayCounter;
void addVar(const T& value, int num);
void resetArray();
void delArray();
void showVar(int num);
private:
T* coreArray;
T* varArray;
};
template<typename T>
void Lottery<T>::addVar(const T& value, int num)
{
coreArray[num]= value;
}
template<typename T>
void Lottery<T>::createArray(int n)
{
delArray();
T *coreArray= new T [n];
T *varArray=new T [n];
}
int main()
{
string ans, n, n2;
int ans2, n1, b2;
cout << "Welcome to R-Lot!" << endl;
while (true)
{
cout << "R-Lot for Numbers (1) or Names (2)? ";
ans=EnterOnlyNumbers();
ans2=stringtonumber(ans);
cout<<endl;
if (ans2==1 || ans2==2)
break;
}
while (true)
{
cout<<"How many units are in the R-Lot? "; n=EnterOnlyNumbers();
n1=stringtonumber(n);
cout << endl;
if (n1>15)
cout << "R-Lot is too big, try another size!"<<endl;
else
break;
}
if ( ans2 == 1)
{
cout<<"Numbers"<<endl;
Lottery<int> Lotto;
Lotto.createArray(n1);
for (int b=0; b<n1; b++)
{
cout<<"Enter value for ["<<b+1<<"]: ";
n2=EnterOnlyNumbers();
b2=stringtonumber(n2);
Lotto.addVar(b2,b);
cout<<endl;
}
cout<<"Done!"<<endl;
Lotto.arrRef(n1);
Lotto.showVar(n1);
Lotto.delArray();
}
else
{
cout<<"Names!"<<endl;
Lottery<string> Lotto;
Lotto.createArray(n1);
Lotto.delArray();
}
return 0;
}
_________________________________________________________________
I'm working on the <int> version of the Lottery<int>Lotto, and whenever I'm at this part:
for (int b=0; b<n1; b++)
{
cout<<"Enter value for ["<<b+1<<"]: ";
n2=EnterOnlyNumbers();
b2=stringtonumber(n2);
Lotto.addVar(b2,b);
cout<<endl;
}
The damn C++ program i use just crash...
-And the Lotto.showVar(n1) won't show the Array correctly... it keeps showing
just this : { }
If anyone could just take a minute to read the code, and help me i'd really appreciate it.
Oh... Thanks for the advice for the pointers.
I'm just doing this to see if I can successfully make a template class program, not really try to reinvent anything...
Hello,may I join.....I need help,can someone tell me about an array...Cause I do my program using array..but when I want to write it say "invalid type"....can someone tell me about an array...