Well, you want to check if all the characters in the string are digits. So, start by assuming that this to be true:
Code:
bool isDigit(const char str[])
{
return true;
}
Obviously, if the first character is a non-digit, this will fail. So, check that your assumption holds for the first character, returning false if it does not:
Code:
bool isDigit(const char str[])
{
if (!(str[0] >= '0' && str[0] <= '9'))
{
return false;
}
return true;
}
But now, if the second character is a non-digit, this still isn't going to work. You need to check your assumption for every character. So, write a loop to check that your assumption holds for each character, returning false if your assumption does not hold:
Code:
bool isDigit(const char str[])
{
for (int count = 0; str[count] != '\0'; ++count)
{
if (!(str[count] >= '0' && str[count] <= '9'))
{
return false;
}
}
return true;
}
Note that I have taken the liberty of changing the parameter to be a pointer to const char instead, and renamed it to str since ch would be misleading.
For this to work though, you really need a null terminated string. If I remember correctly, this would not null terminate to give you a null terminated string:
I suggest using getline instead of get.
By the way, have you been taught about the <string> standard header and the use of std::string objects? If so, then you should use that instead of null terminated strings.
Oh, and do
not use global variables. Your size variable is okay since it is declared const, but you should give it a more descriptive name, e.g., password_max_size.