Hey guys, i am having a huge problem checking the data i input to make sure it is correct. What i am trying to achieve is when i input a value, it will check if the input is all digits and if it is not, check to see if it contains certain alphabets. Thus for example, if i were to input in data such as "11A" , the program will then imform me "There is an important alphabet in the program." This would be my expected output.
Here is the program i have wrote...
int test(string r ){
const int arraySize = 10;
char array2[arraySize2] ={'A','B','E','F','G','H','J','K','N','O','P','Q','R','S','T','U','W','Y','Z'};
for(int cntr = 0; cntr <r.length(); cntr++)
if(!isdigit(r[cntr])){
for(int new1 =0; new1<arraySize2;new1++)
for(int cntr1 = 0; cntr1 <r.length(); cntr1++)
if(array2[new1] == r[cntr1]){
return 2; //will return2 when it finds the same
// char in the array and the string r.
}
else{
return 3; //will return 3 when there is a char
//in the string which isnt in the array
}
}
else {
return 1; // will return 1 when string is all digit.
}
int main()
{
string r = "11D";
test(r);
if(test(r) == 1)
{
cout << "ALL ARE DIGITS" << endl;
}
if (test(r)== 2)
{
cout << "There is an important alphabet in the program." << endl;
}
if (test(r)== 3)
{
// testRoman(r);
cout << "THERE IS AN ALPHABET IN THE STRING WHICH IS NOT IN THE ARRAY" << endl;
}
}
So, the problem i am facing is when i input in data such as 11 or A , the prog will come out the right input. But if i were to put in data such as "11A" , the output coming out will be "ALL ARE DIGITS". The problem which causes this seems to be in the return statement , as once as it finds the first char which is a digit, it will then return 1 and not continue checking the rest of the string. Is there a way i can stop or continue a loop if it has met the condition i stated?
Any suggestions on what i can do or any other way available for me to check my input? Hope for some help. Thanks.