bool isValidDouble (char numbers [], int size)
{
int count;
int Deccount = 0;
for (count=0;count <Size; count ++)
{ if (isdigit(Numbers[count]))
return true;
else if (((Numbers[count]) == '.') && (Deccount == 0))
{
Deccount++;
return true;
}
else
return false;
}
}
void readDouble (char Numbers[], int Size)
{
if (isValidDouble(Numbers, Size))
cout <<"That is a valid number"<<endl;
else {cout<< "That is not valid. Please retry"<<endl;}
}
void main ()
{cout<<"Please enter a real number:"<<endl;
cin.getline(Numbers,Size);
readDouble(Numbers,Size);
}
If I understand your question correctly I think your problem is in the function "isValidDouble(char numbers [], int size)" In the for loop. It will check the first element and return something regardless of what all the other elements are. In other words: if you removed the for loop you would get the same result because after the first iteration of your loop it always returns something.