I have a function which uses an std string parameter to test if there is an alpha character. It would be best to test for only numeric characters but I have not gotten that far just yet. I just am trying to get it to recognize if the input does not have a number in it. If not it loops the error message until there is only numbers. After this I am trying to convert the string to double by use of atof() so it can be returned in main(). I get a debug assertion failed! Message upon runtime which says, expression string subscript out of range if a number is put in. Other wise if a letter has input, it keeps looping its self with the error message. I got my code for the function below. Any one have any clues as to what I am doing wrong? I am out of ideas...
double Bet::betProb(std::string b)
{
bool alphChar = false;
double doubleBet;
for(int i = 0; i < b.size(); i++){
if(isalpha(b[i])){
alphChar = true;
}
}
while(alphChar){
cout << "Error! Bet only with numbers." << endl;
cin >> b;
for(int i = 0; i < b.size(); i++){
if(!isalpha(b[i])){
alphChar = false;
}
}
}
string F=b;
int T=F.size();
char Change[100];
for (int a=0;a<=T;a++)
{
Change[a]=F[a];
}
doubleBet = atof(Change);
return doubleBet;
}